Okay so I am making a tower defense game in GML and I came across a small problem when making a switch statement, I want to have anything from 1-10 to result in a variable changing to 1, anything from 11-20 result in the variable changing to 2, and anything 21-30 to change to 3. It would look something like this. Yes I know I'm new to coding..
switch(test)
{
case (1-10):
test = 1;
break;
case (11-20):
test = 2;
break;
case (21-30):
test = 3;
break;
}
Except for the fact that that does not work and to actually do something like that, in my knowledge you'd have to make a case for every single number in the range which would take ~3 years. Help?
switch
statements don't allow anything like this. They are meant to evaluate several values at once, though you can do the same with anif...else
cascade. Also, you want to evaluate real values, not integer ones, and to do so you need to use logical operators such as<
or>=
and so on,if...else
statement is your choice. BTW this is not GM:S related question, this is basic programming. \$\endgroup\$switch
statement implementations around there. On the other hand, they have one property in common: the only comparison operation they perform is equality between the argument and thecase
values. It isn't possible to specify a value range for numbers, hence it's preferable to use a certain number ofif...else
statements. \$\endgroup\$