Condition- and function-type triggers (CNS) (Read 1231 times)

Started by Just No Point, October 07, 2015, 04:19:59 am
Share this topic:
Condition- and function-type triggers (CNS)
#1  October 07, 2015, 04:19:59 am
  • ******
For historical reasons, two distinct constructs are both called "triggers." The first is what might be more properly called a condition-type trigger, and the second is what might be more properly called a function-type trigger. For instance, in the CNS, a typical state controller might look like

[State 1234, 5]
type = ChangeState
trigger1 = time = 0
value = 0
The entire line "trigger1 = time = 0" is a condition-type trigger. If the expression "time = 0" evaluates to a nonzero value, then the ChangeState controller is executed. If the expression "time = 0" evaluates to zero, then the ChangeState controller is not executed. Thus whether the condition is zero or nonzero affects whether the controller is triggered.

On the other hand, the word "time" appearing in the expression is a function-type trigger. It returns a value, namely, the amount of time that the player has been in state 1234. Note that a function-type trigger doesn't "trigger" anything. It just gives a value that can be acted on within the expression.

To further illustrate the difference, let us consider a different state controller:

[State 1234, 5]
type = VarSet
trigger1 = 1
v = 0
value = time + 5
Note that the condition-type trigger "trigger1 = 1" now contains no function-type triggers within it. Since the expression "1" always evaluates to 1, the controller will be triggered every frame. To determine what value to assign var0, the expression "time + 5" is evaluated. The function-type trigger "time" returns the player's statetime. Then 5 is added and the result is stored in var0.

A complete list of function-type triggers can be found in trigger.html.

In general, which of the two types of triggers is meant is clear from context. Where there is some ambiguity, the terms "condition-type trigger" and "function-type trigger" will be used.