How to use the IF(expression)

The left hand column, labeled sensors, is your if statement. actuators are the… well, the actions the statement does.

by Captain Oblivian

And by me, smile:

Yes you can use logic blocks to do if conditional statements. Have you read this:

And this:

Expressions must be fully qualified

Var start == FALSE

IF(start FALSE) is not the same and doesn’t work as


In the first expression, start should evaluate to false and the statement should be executed, but it is not. However in the second expression the statement will be excuted.

Working Examples:

IF(start==FALSE AND timer<5 TRUE)
IF(start==FALSE OR timer<5 TRUE)

If you are positive everything is correct but something doesn’t work, then delete it. Delete all of it, such as the sensor, the controller and the actuator.
Perhaps even delete any actions that function relates to in other objects also. Then add everything again. Chances are there was a typo or a space that you just didn’t see in the wrong place.
I spent a day working such a problem. I had two almost identicle functions, yet one didn’t work. I changed and retyped, and disconected, etc all day.
At my wits end, my cursor landed in a to: field and a space was highlighted. I looked at it, thinking what? Some how (maybe the cat) a space was entered in tha field. The GUI doesn’t recognize object names in the To: field of the message actuator like it does in other Ob: name fields.


On the picture of the logic, there are missing parentheses after your expressions…

Very cool!!! The only thing is that I think you’re missing parentheses at the end of your expressions (in the picture of the logic).

I believe they are called “If Then statements” or maby “Iff then statements”. (no I did not spell if wrong, iff = if and only if)

No, it’s:

if something:
     do something
     do something else

It’s an “if else” statement

And do note the operators, it must be ==. not = or you get a syntax error.

The different operators for code.

< less than
> greater than
<= less than or equal to
>= greater than or equal to

There are probably lots of different statements.

This isnt for python, its for the if(expression) in the logic bricks.

Yes there are many ifelse and if elseif else if else statements. And then there are the case statements, very similar to if else logic.

Turin: Yes you are right, thats too funny. I was pretty tired when I made the logic blocks for that demo.

if else if else if else…

yeah, sorry! I’ve been into WAY to many if/else statements in MGP. Thanks for the reminder about the expression controller :slight_smile: