Way to use case and switch instead of if statements in lua?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’d like to know if using case and switch is possible in LUA
  2. What is the issue? Include screenshots / videos if possible!
    I’m making a plugin that checks lots of values and using lots of if statements can fill the screen and make things look unorganized compared to switch and case
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried to search for solutions on the devforum but couldn’t find anything.

Example of case and switch:

switch (<Expression>) {
    // Expression evaluates to a single value.

 case <Value1> : //Case is picked when expression gives Value1. 
                 <Statement1>;
                 <Statement2>;
                 break;
 case <Value2> :
                 <Statement1>;
                 <Statement2>;
                 break;
 .
 . //So on.
 default : // When value of expression didn't match with any case
                 <Statement1>;
                 <Statement2>;
                 break;
}

There arent switch statements, but you can bypass this with tables. I’m not sure how but there are answered posts with your exact question.

Could you please link one? I can’t seem to find it.

There are more. Search “switch statements Roblox studio”

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.