Switch/case range syntax question

Game Editor comments and discussion.

Switch/case range syntax question

Postby yttermayn » Fri Mar 11, 2011 3:28 am

If I have a range of values I want to trigger a certain case using the switch statement, what is the syntax for that in game editor?

Like if I want the numbers 1 through 3 to be included in the first case, 4 through 20 in the second case, etc.
yttermayn
 
Posts: 48
Joined: Sun Nov 25, 2007 4:10 pm
Score: 2 Give a positive score

Re: Switch/case range syntax question

Postby rykein » Fri Mar 11, 2011 4:12 am

you cant. if you are dealing with ranges you should probably use if. for your example though you might do this.
Code: Select all
switch(variable)
{
    case 1:
    case 2:
    case 3:
    break;

    default:
    if(variable>=4 && variable<=20)
    {
        //
    }
    break;
}


though at that point you might as well use ifs.
rykein
 
Posts: 63
Joined: Mon Jul 26, 2010 7:26 am
Score: 6 Give a positive score

Re: Switch/case range syntax question

Postby yttermayn » Fri Mar 11, 2011 5:27 am

That's what I was afraid of. Thanks!
yttermayn
 
Posts: 48
Joined: Sun Nov 25, 2007 4:10 pm
Score: 2 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron