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

Events & Timers

Events are the driving force behind your scripts...

 

Overview

When Warzone is processing your script, everything else in the game stops. So your script can't just run in a never-ending loop - it has to do something, then stop, so that Warzone can get on with other stuff. So, without events, your script would do one thing, then stop and never start again. In fact, it wouldn't even start in the first place - everything has to be event driven!

Warzone provides a number of pre-defined events, and some functions which allow you to create custom events (see bottom of this page). When an event is triggered, your event listener/handler (a function) should perform some task based on that event. For example, if a droid gets attacked you might want to send it for repairs or retreat it to a safe distance.

The normal JS API only allows you to attach a single event handler to each event - which is fine for most scenarios. However, if you need to attach multiple events you'll need to use uTardis() that's part of Util.js.

Pre-defined events

Warzone's qtscript.cpp defines and triggers a large number of extremely useful events. If one of these events is triggered before you are ready to do something (eg. your Laser Satellite Command Post is ready to attack but you don't yet have a suitable target) you can set up a custom event (using queue() for example) to do something later in the game.

Custom events

You can create custom events using Timers:

  • setTimer() – create a repeating schedule to trigger a function call
  • queue() – create a one-time schedule to trigger a function call
  • removeTimer() – cancel a timed or queued function call

Deprecated events

In Warzone 3.1, there was another custom event mechanism:

  • bind() – set up an event that will be triggered when a specific object is destroyed (any object, an owner)

In Warzone 3.2 and above, use eventDestroyed() instead – it was updated to trigger when any object, of any type or player, is destroyed.

Availability

New events have been added at various stages of Warzone's evolution.

For a summary of availability and changes, see: Events by version.

See also

Related documentation:

  • Environment Sequences – learn about the sequence of events, and what you can do at different stages of that sequence