• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Inline IF Statement

Okay simple questions for your Wednesday Morning...I come from JS and I know how to write up an inline IF statement there but doesn't seem to quite apply to GML.

JS would be
Code:
if (A) ? B : C
GML Inline IF?
 
H

Homunculus

Guest
You can use ternary operators in GMS2, but not in GMS1. The syntax is the same as in javascript, but I want to point out that the code you posted above wouldn't work even in JS, this kind of conditions do not use the if operator. Therefore the above should be:
Code:
A ? B : C;
 
You can use ternary operators in GMS2, but not in GMS1. The syntax is the same as in javascript, but I want to point out that the code you posted above wouldn't work even in JS, this kind of conditions do not use the if operator. Therefore the above should be:
Code:
A ? B : C;
Awesome, thank you! Im still missing something I think... It gives me the red x.

Code:
randSp <= 0 ? image_speed = .5 : image_speed = 1
 
H

Homunculus

Guest
Not sure if that would work, I generally use it like this:
Code:
image_speed = randSp <= 0 ? .5 : 1
EDIT: can confirm that your code throws an error, I actually expected it to work honestly
 
Last edited by a moderator:
Top