Q6: Timers and save/load

Seeing as this seems to have become a bit of a de-facto forum for Q6... I was trying to figure out timed events and save/loading in Q6, and just want to make sure that what I'm doing isn't naive for a reason I'm not currently thinking of.

Currently, despite what is indicated in the wiki, the registerTimedEvents function cannot be called post game setup unless saving is disabled due to:

if (world.isCreated && !settings.saveDisabled) {
  errormsg("Attempting to use registerTimedEvent after set up.")
  return
}

Removing this check leads to timed events functioning normally within one load instance, but the contents of game.eventFunctions are lost upon save/loading, so while the event still fires normally at the correct time following a load, it just errors out because the actual function call is no longer present. I fixed this by simply adding "eventFunctions" to saveLoadExcludedAtts.

To my understanding, that means that the eventFunctions are always created right upon navigation to the game page, and never touched by the save/load functions, so they should always be what they were upon game initialization. Or am I misunderstanding something?


Thanks for highlighting. I have not used timers in anger, and they cannot be unit tested, so it is an area that is not so well covered.

I think your method will work, because there is a special save/load bit to cover that. Quest will put the data in an array of dictionaries, which generally will not be saved, but should be in this case. The warning then is a bug.

When written, the save/load would not save arrays of numbers. That is not now the case, so a better technique is possible, saving the data in multiple, simple arrays that will get saved. I have re-written it to do that, but it does change the whole system, and instead of registered your functions, you now create them in setting.js, and set them going with util.registerTimerEvent (though the functions you set up are the same, and the parameters to util.registerTimerEvent the same as before, so hopefully easy enough to change).

Note that the functions are "timer" not "timed".

This is not in a release yet; you would need to get the latest files from Github. The updated files are _settings, _util and _world. The Wiki has been updated, so details there.


This topic is now closed. Topics are closed after 14 days of inactivity.

Support

Forums