(info) Other great resources: Official JS API docs, Scripting Forum

eventGameInit()

This event is triggered once at the start of a new game before the map is ready.

 

Overview

This event is only ever triggered once when a new game starts, it is not called when a saved game is loaded.

When the event is triggered, all your scripts have been loaded and basic game initialisation is complete:

  • You can retrieve basic information about the game, such as playerData[] and use most if not all of the enum functions (such as enumDroid() and enumStruct()
  • Do not issue any commands (such as production, research or droid orders) because the game hasn't properly started yet.
  • Any custom events (setTimer()queue() or bind()) will not be triggered until after eventStartLevel().

The eventGameInit() event is primarily aimed at script initialisation or, in the case of rules.js, player initialisation.

If you want to set custom events (timers, etc.), it is best practice to do that in eventStartLevel(). Furthermore, it is best practice to only issue orders (research, production, attacks, etc.) after eventStartLevel() – usually triggered by some other event or timer.

(warning) It is recommended that you read Environment Sequences to gain a fuller understanding of this event in context of the initialisation sequence of a new game / level.

Syntax

function eventGameInit() {
  // do stuff
}

Parameters

This event has no parameters.

Return value

Warzone does not process your event handler's return value.

Example

Choose a research path based on AI difficulty
var insaneResearchPath = [ /* research items here */ ];
var hardResearchPath = [ /* research items here */ ];
var mediumResearchPath = [ /* research items here */ ];
var easyResearchPath = [ /* research items here */ ];


function eventGameInit() {
  // choose a research path
  switch (difficulty) {
    case INSANE: {
      global.researchPath = insaneResearchPath;
      break;
    }
    case HARD: {
      global.researchPath = hardResearchPath;
      break;
    }
    case MEDIUM: {
      global.researchPath = mediumResearchPath;
      break;
    }
    case EASY: {
      global.researchPath = easyResearchPath;
      break;
    }
  }
  // but do not start any research yet...
  // research can only be started *after* eventStartLevel()
}

Availability

Requires:

  • Warzone 3.1 Beta 1 and above.

See also

Related articles: