Translations

Know another language? Translate this tutorial!

What you may not know about logical expressions

Favourite 16 favourites
Tutorial written by WaltanOriginally published on 11th, April 2015 - 4 revisions

Many of you are using the 'regular' way to create conditions and actions:


In this little tutorial, I'll tell you about something new, which will help you to increase your programming skill.

If you carefully read the manual, you may have noticed the following:


Looks interesting, so how do we use it?

Here is how I changed actions in the first screenshot:


An explanation:

If you click on Sprite, it fill add some number to Sprite.AnimationFrame. But what number it will be? Here works our logical expression:

    sprite.Increase = 1? 1 : 0

That means: if variable Increase = 1 then it will add 1, in any other way, it will add 0;

You can make any logical expression you want, using this logical operators:
= - EQUALS
<> - NOT EQUALS
& - logical AND
| - logical OR

Here is some examples:

First

    (self.var1 = 0) | (self.var2 = 0) ? 0 : 100

This one just check if var1 or var2 are greater than 0.

Second

    ((self.var1 > 0) & (self.var2 > 0)) & (self.var2 <> 100) ? 0 : 100

It check if var1 and var2 are greater then 0 and if var2 is not equal 100.
It might be usefull to make an exception in some cases.

Third

You can also put logical expression into results of logical expression =D

    self.Var1 > 0 ? (self.Var2 = 0 ? 1 : 0) : (self.Var3 = 0 ? -1 : 0)

As you can see, it checkes:

If var1 is greater than 0, if so, if var2 is equals 0 we will get 1, else 0.

If var1 is not greater than 0, then it will check if var3 is equals 0 and will get us -1, or 0 in any other case.

Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.

Comments

0
Rable 3,484 rep

Very useful, thanks a lot!

Wednesday, August 02, 2017 at 8:31:27 AM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.