Changes between Version 2 and Version 3 of Triggers


Ignore:
Timestamp:
Jun 22, 2014, 11:55:22 AM (10 years ago)
Author:
sanderd17
Comment:

Info on registering triggers

Legend:

Unmodified
Added
Removed
Modified
  • Triggers

    v2 v3  
    3434This should show a yellow warning in the top left of your screen when the map loading is finished.
    3535
    36 '''Tip:''' See [wiki:Logging Logging] for more logging options.
     36'''Tip:''' See [wiki:Logging Logging] for more logging options, and use `uneval(data)` to transform any JS data into human-readable text.
    3737
    3838== Writing the trigger scripts ==
     
    4242=== Action functions ===
    4343
    44 Actions are regular JavaScript functions, registered under the `Trigger` prototype.
     44Actions are regular JavaScript functions, registered under the `Trigger` prototype. Actions called by triggers always receive a data object with more information about the event that just happened. How the data looks depends on the actual event. See the table below (TODO ''guess we need to make a table'').
    4545
    4646{{{
     
    8585    this.executedTriggers = 0;
    8686    this.killedUnits = 0;
     87    this.state = "initialising";
    8788}
    8889}}}
     
    104105
    105106== Registering functions ==
     107
     108When you have your actions made, you need to bind them to a certain event. This is done via the predefined RegisterTrigger function. Triggers can be enabled in any method, but you usually need to enable some at the start of the game. You can use the following schema:
     109
     110{{{
     111#!js
     112Trigger.prototype.InitGame = function(data)
     113{
     114    var myData = {"enabled": true};
     115    this.RegisterTrigger("OnPlayerCommand", "MyAction", myData);
     116};
     117}}}
     118
     119The first parameter of the trigger is the event on which it will be executed. In the example, the trigger will be executed for every player command. See the table below for a list of all possible events (TODO ''we do need that table''). The second parameter is the name of the action, which has to be defined under the Trigger prototype. And the third part is a data object. For most triggers, this data will be just enabled = true or false. But for more complicated triggers (range triggers, time triggers, ...) this data can contain other elements, such as the the distance of the range trigger, or the interval of the timer. Again, see the data in the table below.
     120
     121The combination of event and action name must be unique. This combination can be used to enable and disable triggers. Registering a trigger twice isn't possible, and tou will be warned when you do that.
     122
     123Enabling and disabling triggers happens as shown:
     124
     125{{{
     126#!js
     127this.EnableTrigger("OnPlayerCommand", "MyAction");
     128this.DisableTrigger("OnPlayerCommand", "MyAction");
     129}}}
     130
     131You can enable and disable triggers as often as you want.