Doc:2.6/Manual/Game Engine/Logic/Controllers/Expressions
目次
Game Expressions
A controller can evaluate an expression in order to send a positive or negative pulse to the connected actuators:
- if the expression evaluates to
True
, the controller sends a positive pulse to the connected actuators. - if the expression evaluates to
False
, the controller sends a negative pulse to the connected actuators.
Variables
You can use:
- sensors names,
- properties: assign a game property to an object and use it in a controller expression.
These cannot contain blank spaces.
Operations
Mathematical operations
Operators: *, /, +, -
Returns: a number
Examples: 3 + 2, 35 / 5
Logical operations
- Comparison operators: <, >, >=, <=, ==, !=
- Booleans operators: AND, OR, NOT
Returns: True or False.
Examples: 3 > 2 (True), 1 AND 0 (False)
Conditional statement (if)
Use:
if( expression, pulse_if_expression_is_true, pulse_if_expression_is_false )
If the controller evaluates expression
to True:
- if
pulse_if_expression_is_true
isTrue
, the controller sends a positive pulse to the connected actuators. - if
pulse_if_expression_is_true
isFalse
, the controller sends a negative pulse to the connected actuators.
If the controller evaluates expression
to False:
- if
pulse_if_expression_is_false
isTrue
, the controller sends a positive pulse to the connected actuators. - if
pulse_if_expression_is_false
isFalse
, the controller sends a negative pulse to the connected actuators.
Examples
Given the object has a property coins
equal to 30:
coins > 20
returns True (the controller sends a positive pulse to the connected actuators).
Given the object has:
- a sensor called
Key_Inserted
equal to True, - a property named
Fuel
equal to False,
Key_Inserted AND Fuel
returns False (the controller sends a negative pulse to the connected actuators).
This is the same as doing:
if (Key_Inserted AND Fuel, True, False)
Instead, you could do:
if (Key_Inserted AND Fuel, False, True)
to return a positive pulse when Key_Inserted AND Fuel
returns False.
You can also do:
if ((Key_Inserted AND Fuel) OR (coins > 20), True, False)
This expression returns True, hence in this case the controller sends a positive pulse to the connected actuators.