if¶
Syntax¶
Parameters¶
<predicate>- A truthy or falsey numeric expression.
<statement>- A valid FRED statement, such as an action or an assignment.
Description¶
Conditionally execute an action or transition.
The agent executes the given action or transition when the given predicate
evaluates to 1 (true). The predicate is evaluated with respect to the current
agent, and in this manner an if statement allows individual agents to behave
differently within the same state.
Truthy and Falsey Values¶
Like in many programming languages, FRED's numeric expressions can be evaluated as either true or false. Values that evaluate to true are considered "truthy", and values that evaluate to false are considered "falsey".
In FRED, a value of 0 is falsey, and all non-zero values are truthy.
Examples¶
In this example state, the statements are evaluated based on the agent's age.
The final value of x will be 11 for agents 10 yrs old or younger, and 21 for
all other agents.