In this simple demonstration of the problem there is a blue cube. When it falls and collides with an object having the property "obstacle" (while the player is also performing some action) the cube should turn red. What kind of expression syntax can accomplish this?

enter image description here

If an And Controller is used instead, the cube turns red. The problem is that it will do this whether the property of the object it collides with is True or False. I want it only to happen if 'obstacle'==True. How can this be accomplished? Thanks.


1 Answer 1


No Expression Required

I don't know if there's no way for a Collision Sensor to pass along the value of the property it's watching. Instead, we can have the object collided with send a Message, and receiving that Message can be one of the conditions required by an And Controller in order to trigger the Actuator.

Obstacle Logic

Obstacle logic. If ticked, obstacle == True. Then if this object is collided with, the cube changes color upon collision.

Cube Logic

The Cube's And Controller needs three conditions: Collision with an "obstacle", some player action, and a Message from the obstacle object.

As for expressions, here is a reference. I'll re-post it below:

Table 26-1. Valid expressions

Expression type  Example
===============  =======
Integer number   15
Float number     12.23224
Booleans         TRUE, FALSE
Strings          "I am a string!"
Properties       propname
Sensornames      sensorname (as named in the LogicBrick)

Table 26-2. Arithmetic expressions

Expression       Example
==========       =======
EXPR1 + EXPR2    Addition, 12+3, propname+21
EXPR1 - EXPR2    Subtraction, 12-3, propname-21
EXPR1 * EXPR2    Multiplication, 12*3, propname*21
EXPR1 / EXPR2    Division, 12/3, propname/21
EXPR1 > EXPR2    EXPR1 greater EXPR2
EXPR1 >= EXPR2   EXPR1 greater or equal EXPR2
EXPR1 < EXPR2    EXPR1 less EXPR2

Table 26-3. Boolean operations

Operation        Example
=========        =======
NOT EXPR         Not EXPR
EXPR1 OR EXPR2   logical OR
EXPR1 AND EXPR2  logical AND
EXPR1 == EXPR2   EXPR1 equals EXPR2

Conditional statement: IF( Test, ValueTrue, ValueFalse )


Table 26-4. Expression examples

Expression           Result          Explanation
==========           ======          ===========
12+12                24              Addition
property=="Carsten"  TRUE or FALSE   String comparison between a Property and a string
"Erwin">"Carsten"    TRUE            A string comparison is done

And if anyone figures out syntax for testing the value of a property, please share.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .