• All, Gmail is currently rejecting messages from my host. I have a ticket in process, but it may take some time to resolve. Until further notice, do NOT use Gmail for your accounts. You will be unable to receive confirmations and two factor messages to login.

Solved What does the following code do? And why does it only return -1 or 1?

Question that is answered or resolved.

NONAME01150

New member
Like what i've written above, what (or how) does the following code work? Cause it seems to return either -1 or 1:
side = (facing == 0) ? (-1) : (1);
I had found this while browsing "SFFG Plus"'s scripts, searching for any way to check for the Y velocity.
The "facing" seems to be referencing the entity property "direction".
I'm just curious on how this piece of code works.
 
@NONAME01150

That's called a Ternary operator. It acts as a one line shortcut for simple conditional IF statements.

Code:
value = (condition) ? (value if true) : (value if false);

Functionally, it is identical to writing this:

C:
if(facing == 0)
{
    side = -1;
}
else
{
    side = 1;
}

HTH,
DC
 
Back
Top Bottom