Page 1 of 1
eventStartLevel() -- is it also called after loadLevel()?
Posted: 10 Mar 2012, 04:28
by aubergine
I'm just documenting eventStartLevel() and was wondering if this event also gets called after loadLevel()? I don't really know anything about, or understand, the loadLevel() function so I'm a bit stumped trying to work out these two API features.
As eventStartLevel() seems to be the preferred trigger point (at least for AI scripts) to initialise scripts and timers, etc., it would be useful to know if it's only ever called once per game (when game is started new or loaded from save game) or whether it might get called more than once in the same "game session".
Also, any info on loadLevel() much appreciated as I'll be documenting that soon too

Re: eventStartLevel() -- is it also called after loadLevel()
Posted: 10 Mar 2012, 10:41
by Per
I don't really know that much about what goes on behind loadLevel() yet.
eventStartLevel() should only be triggered once per game. It is not called when a game is loaded (which should be completely transparent to scripts for now).
Re: eventStartLevel() -- is it also called after loadLevel()
Posted: 06 Nov 2012, 00:46
by aubergine
Sorry to necro this old topic, but I was wondering if any more is known now about eventStartLevel() in the context of a new level being loaded in a campaign?
Specifically, it has become customary for scripters to use eventStartLevel() to define a number of timers and/or queued function calls.
In a campaign, the player starts a new mission thus firing eventStartLevel() which in turn starts timers running. If then loadLevel() is used, and eventStartLevel() is fired once more after that level loads, what happens to the timers that were set in the previous triggering of eventStartLevel()? If they are still running, and eventStartLevel() gets called again due to a level being loaded, would this mean that there could be multiple timers running for the same function thus doubling the number of times a function is being run (because now it has 2 timers hitting it)?
Re: eventStartLevel() -- is it also called after loadLevel()
Posted: 07 Nov 2012, 17:25
by milo christiansen
I always used EVENTGAMEINIT in WZScript. (I think it has some underscores in its name but IDK) Any reason this won't work now?
Re: eventStartLevel() -- is it also called after loadLevel()
Posted: 07 Nov 2012, 18:45
by aubergine
There is eventGameInit in the JS API, which is called once at the start of a new game.
Most JS scripts are using eventGameInit() to do some code initialisation, and then eventStartLevel() to set a bunch of timers / queued function calls.
eventGameInit() from my understanding is the point at which you can start querying the map and game objects (but not issue any commands / research / production). Then it's only after eventStartLevel() that you can start doing things like research, etc.