Gerards Lua Proposal

From WarzoneWiki

Jump to: navigation, search

The goal of this proposal is to support as clearly and intuitively what warzone calls triggers and events (but which are in fact events and event handlers) There are different types of events and all will be described.

Contents

Interface

Conditional Events

These events execute their event handler when the expression evaluates to true. Proposed syntax:

   conditionalEvent( eventHandler, "a > b", 1.0)

This will cause the eventHandler to be executed when a > b. This will be first checked after one second, and the checks will repeat every second.

Callback Events

These events happen when for example a droid is built. Proposed syntax:

   callbackEvent( eventHandler, CALL_DROIDBUILT )

Scripts will have to be enhanced to provide the following line of code to filter out events they are not interested in, as the trigger no longer does this:

   if droid.player != me then return end

Init Events

This event is called at the start of the game, to allow scripts to set up.

   initEvent(eventHandler)

Repeating Events

   repeatingEvent(eventHandler, 1.0)

Delayed Events

   delayedEvent(eventHandler, 1.0)

Special Topics

Repeating with variable period

An event which repeats with a dynamic period can be implemented like:

   function eventHandler()
       ....
       delayedEvent( eventHandler, time_to_wait)
   end

The powerful conditionalEvent

The conditionalEvent is actually quite powerful, as it allows a fourth parameter, repeating, which is by default set to true. This way an init event is equivalent to:

   conditionalEvent( eventHandler, "true", 0 , false)

and a repeatingEvent:

   conditionalEvent( eventHandler, "true", 1.0 , true)

and a delayedEvent:

   conditionalEvent( eventHandler, "true", 1.0 , false)

Implementation

Init, repeating and delayed events will be created as conditionalEvent. A function tick() is called every frame. This function iterates over all events, and checks whether it is time to check. Then, it will evaluate the expression and if it evaluates to true, the eventHandler will be called. If the event was not repeating it will be removed from the list before calling the eventHandler.

Callback triggers are invoked from C. There for each separate script running, all functions registered for that event will be called with arguments specific to the event. No distinction is made for what player and what group, as currently happens. The scripts will have to check for this themselves.