• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Do case statements require curly braces?

ac585318

Member
I'm new to GMS2 and am curious... Do case statements require curly braces?

I've seen been going through tutorials and some of them are using curly braces in the case statements and some not.

I breifly read that apparently in the C programming language they are needed for declaring variables in a case statement but do they serve any similar purpose for case statements in GML? I couldn't find/see anything on this myself.
 

Simon Gust

Member
They don't, as case statements are basically curly brackets themselves.
Code:
case 0:

break;
everything that is in between case and break is run, it can also be stacked
Code:
case 0: var t = current_time; var i = 5; state = "walk"; break;
 

Evanski

Raccoon Lord
Forum Staff
Moderator
you dont need to add the { }
but if its more then one line of code its good practice to add the { }
 
Top