SA-MP Forums Archive
value - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: value (/showthread.php?tid=273893)



value - Gh0sT_ - 03.08.2011

Is that possible to check is variable value is 20, 40, 60, 80, 100, 120 and so on without checking it with || (I mean if(something == 20 || something == 40) and so on.


Re: value - PrawkC - 03.08.2011

Could use switch case
pawn Код:
switch(var)
{
case 20:
case 40:
etc
}

pawn Код:
switch(var)
{
case 20..120: //I think thats how it works, or might be 3 dots
}
^ but that'd be 20, 21, 22 etc.


Re: value - Mean - 03.08.2011

Switch.
pawn Код:
switch( varname ) {
    case 20, 40, 60, 80, 100, 120: {
        //Your code goes here.
    }
    default: {
        //If it is non of these values.
    }
}
EDIT: I was late.


Re: value - Gh0sT_ - 03.08.2011

Your first example will work same as if(something == 20 || something == 40)

And second - this will include values like 21, 35, 47 and so on. I need to check is it only 20, 40, 60, 80, 100, 120, 140, 160, 180 and so on.

Mean: same as first post.. I will need to add values, there's other way I think?


Re: value - PrawkC - 03.08.2011

Then no there isn't.

you're saying you want a different of checkign if something equals something, other than using '==' or switches? I don't see how that'd be done.


Re: value - Mean - 03.08.2011

Why don't you want to use switches/if? I see no reason not to.


Re: value - Toreno - 03.08.2011

Mind If I ask, but can you please tell us why do you need to check too much?
We might find you an easier way instead of chicking them all.


Re: value - Gh0sT_ - 03.08.2011

for example: if speed camera detected player 20 times, then he will lost car license, I mean if 20, 40, 60, 80, 100 times and so on.


Re: value - Toreno - 03.08.2011

Just use the switch then, can't think about a way.


Re: value - Gh0sT_ - 03.08.2011

damn, that would be fuckin long?

case 20, 40, 60, 80, 120, 140, 160, 180, 200.. D.A.M.N :O