Page 1 of 1

Load sequence

Posted: 07 Feb 2013, 10:21
by aubergine
When a game is loaded, is this the sequence of events...?

1. Create environment
2. Define JS API native features on the global object
3. Eval the main script (which in turn will load any includes)
4. Restore saved globals / triggers / groups
5. Trigger eventGameLoaded()

I tried reading the C++ in qtscript.cpp but it melted my brain.

Re: Load sequence

Posted: 07 Feb 2013, 10:59
by Per
It is not easy to follow, I know, but the above interpretation seems correct.

Re: Load sequence

Posted: 07 Feb 2013, 13:18
by aubergine
After the load sequence completes, will the next check for triggers (eg. queued function calls) be at gameTime of the save point, or gameTime+1 or gameTime+100?

I'm trying to backport eventGameLoaded() to Warzone 3.1.

I've got an accessor property, the value of which will be stored in save games. When the game loads, the value is restored triggering the setter function of the accessor property. In that setter function, I want to queue a call to eventGameLoaded() in such a way that it will happen immediately after the load cycle completes (I assume events are disabled during that process) and ideally before any other saved triggers start kicking in.

So, I'm wondering if queue("eventGameLoaded", 0) will do the trick in my setter function, or whether there would be some better way to do it?

Another approach would be to queue("eventGameLoaded", 0) as soon as my script instantiates, then removeTimer("eventGameLoaded") if eventGameInit() gets called.

Both approaches rely on a queue() using 0 delay. However, I noticed in qtscript.cpp this comment:

Code: Select all

struct timerNode
// implement operator less TODO
Which makes me worry that if I specify 0 ms in my queue() call, that my queued call won't trigger if the timer system kicks in after the restored gameTime has changed (although I believe it only increments in blocks of 100ms so that might not be a problem?).

Re: Load sequence

Posted: 07 Feb 2013, 13:35
by aubergine
BTW, here is code I have so far:

Code: Select all

		function saving() {
			// make sure this isn't a script poking around
			if (!arguments.callee.caller) {
				Native.queue("eventGameSaved", 0); // call eventGameSaved() after save cycle
				eventGameSaving(); // call eventGameSaving() now
			return now;
		function loading(val) {
			if (val < now) {
				// clear saved eventGameSaved trigger
				// make sure eventGameLoaded is first event triggered after load cycle completes
				Native.queue("eventGameLoaded", 0);
* global = pointer to global object (like engine->globalObject() in C++)
* Native === global
* .addAccessor() adds a hidden, non-configurable getter/setter property to an object
* now is a global accessor property that returns (new Date()).getTime()

Re: Load sequence

Posted: 07 Feb 2013, 15:13
by Per
I think script makers should not make assumptions about the order of events, or exactly in which frame events are fired, since these things may change. I'm not sure what will happen in your scenario above, nor am I sure if 3.1 and master will behave identically.

Re: Load sequence

Posted: 07 Feb 2013, 15:20
by aubergine
That code is wrapped in a check so that it only gets invoked on Warzone 3.1 branch (no need for it on 3.2 as the events are natively supported). It's basically a backport of the WZ 3.2 save/load events, so that I can use WZ 3.2 features on 3.1 code, which in turn is so I can get NullBot 3 running on WZ 3.1.