Variables
Variables are used to store information that can later be used in a filter. Values are changed using the Actions & Triggers mechanic. Afterwards, they can be used as a Filter after meeting a certain number or range. You can define as many variables as you want, and all variables must have a scope defined.
Variable Element
Element | Description | Value/Children |
---|---|---|
A node containing the variables for this map. | Variables | |
Sub-elements | ||
An individual variable. | Variable Attributes |
Variable Attributes
Element | Description | Value/Children |
---|---|---|
The ID for the variable. | String | |
Defines what the variable will be applied to. NOTE:Variables scoped to a player will give each player a unique value. | , , | |
Sets the initial value of the variable. | Number |
Setting Variables
Setting variables are done inside the Actions & Triggers mechanic.
The <set>
action which changes the variables, waits to be called by a trigger after a filter activates it.
The value
attribute can do any basic mathematical expressions.
Example
<actions>
<action id="increment-flag-cap" scope="team">
<!-- increments the current value by 1 -->
<set var="flag_captures" value="flag_captures+1">
</action>
<trigger filter="flag-cap-filter" action="score-points" scope="player"/>
</action>
...
<!-- Sets some_variable to 0, 1, 2, 3, or 4 randomly -->
<set var="some_variable" value="floor(random() * 5)"/>
...
In this example, the flag_captures
variable will increment by 1 after a player completes flag-cap-filter
.
Using a Variable In a Filter
The variable can then be used in the Variable Filter to be utilized in another Action or other module that uses filters. The variable filter can match for a single number or a range of numbers.
Example
<!-- Match if next_post has a value of 1 -->
<variable id="next-blue" var="next_post">1</variable>
<!-- Match if t_score is >= 100 -->
<variable id="reached-score" var="t_score">[100,oo)</variable>
<!-- Match if t_score is between 5 and 10 (including 5 and 10) -->
<variable id="reached-score" var="t_score">[5,10]</variable>
<!-- Match if t_score is between 5 and 10 (excluding 5 and 10) -->
<variable id="reached-score" var="t_score">(5,10)</variable>
<!-- Match if t_score is between 0 and 10 (including 0 and excluding 10) -->
<variable id="reached-score" var="t_score">[0,10)</variable>
Examples
In this example, when a player first enters region-a
, the team score and later the player score is
increased by 5. The second time the same player enters, the team will score an additional 10 points,
with the player score continuing to increment by 5. Once the team gets 100 points or higher, a message indicating this will be sent.
<variables>
<!-- Initializes the variables -->
<variable id="team_score" scope="team"/>
<variable id="player_score" scope="player" default="5"/>
</variables>
<actions>
<action id="score-points" scope="player"/>
<!-- team_score = team_score + player_score -->
<!-- Adds the player's score to the team score -->
<set var="team_score" value="team_score+player_score"/>
<!-- Adds 5 points to the player's score -->
<set var="player_score" value="player_score+5"/>
</action>
<!-- Triggers the above score-points action when a player enters region-a -->
<trigger filter="region-a" action="score-points" scope="player"/>
<!-- Sends a message to the team once the filter reached-score passes Allow -->
<trigger filter="reached-score" action="completed" scope="team"/>
<message id="completed" text="The team reached 100 points!"/>
</action>
<filters>
<!-- Allows when the t_score variable is greater than or equal to 100 -->
<variable id="reached-score" var="t_score">[100,oo)</variable>
</filters>