eventStartLevel() -- is it also called after loadLevel()?

For AI and campaign script related discussions and questions
Post Reply
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

eventStartLevel() -- is it also called after loadLevel()?

Post 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 :)
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: eventStartLevel() -- is it also called after loadLevel()

Post 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).
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: eventStartLevel() -- is it also called after loadLevel()

Post 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)?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: eventStartLevel() -- is it also called after loadLevel()

Post 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?
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: eventStartLevel() -- is it also called after loadLevel()

Post 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.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply