• 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!

SOLVED Quick one on the 'Switch' statement.

oldnoob

Member
Hi all,

May I ask if I'm getting the Switch statement wrong, below? (it's in the step event)

No matter how many times I run the code, the second case (where DIR=2) always plays out. However, if I physically make DIR=1, then Case 1 will be performed ...so maybe it's not the Switch command, but the value of DIR? Why does this code always assume DIR equals 2 ?

I'm confused.


1587533346305.png
 
Last edited:

oldnoob

Member
Update:

Right, I've switched the CASEs around, so it's now...

1587534988402.png

And now, it always assumes DIR equals 1 - which leads me to believe it's something about how I'm using the Switch statement or the ordering of the Case checks.

Still confused.
 

oldnoob

Member
Well goodness me, I think I found the issue.

Turns out Random_Range isn't really random without Randomize(). Quite how that would affect the order of my CASE checks (above) I don't know.
 

ceaselessly

Member
I believe this might be because you are using random_range, which allows for decimal returns, instead of irandom_range, which would choose either 1 or 2. As the cases are 1 or 2, I believe they will default to the second case if dir equals anything else besides 1 or 2.

Edit: Please disregard; I missed that you were rounding, and I just saw your reply. Did setting randomize at game start help?
 
Top