switch issue - 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)
+--- Thread: switch issue (
/showthread.php?tid=305811)
switch issue -
PawnoQ - 23.12.2011
hi,
with if statements it works fine but as soon as i do it with switch case the compiler crashes, whats wrong with it?
pawn Код:
switch(GetPlayerMoney(playerid))
{
case 1000000 .. 1999999:
{
SetPlayerArmour(playerid,10);
}
case 2000000 .. 2999999:
{
SetPlayerArmour(playerid,20);
}
case 3000000 .. 3999999:
{
SetPlayerArmour(playerid,30);
}
case 4000000 .. 4999999:
{
SetPlayerArmour(playerid,40);
}
}
regards.
Re: switch issue -
Mini` - 23.12.2011
I can't find anything wrong with it, and I'm sitting here reading the wiki about switch statements... Are you sure there's not a problem with the code before this?
Re: switch issue -
PawnoQ - 23.12.2011
100% sure as i commented this code and without this part of code it worked like a charm
Re: switch issue -
Kar - 23.12.2011
switch statements don't work with very large values, that's what ******'s is trying to say. I had a very similiar problem.
Re: switch issue -
PawnoQ - 23.12.2011
thx alot
@ ******: i dont change from things that work to things that dont work, im just playing around with things
I often hear that switch shall be more efficient than if statements so i also tried it with this method.
(i know, in my case you would not notice any difference in speed i guess...)
But i have a further question:
what would be faster or whats the difference between:
1.
pawn Код:
new money;
money = GetPlayerMoney(playerid);
if(money < 1000) return //...
2.
pawn Код:
if(GetPlayerMoney(playerid) < 1000) return //...
What method would be better to use? I know its maybe a stupid question but i find it interesting as every scripter prefers another method
Re: switch issue -
Kar - 23.12.2011
It's a question to ******, but I'd use the second one? unless you planning on using GetPlayerMoney multiple times.
E.G Instead of calling a function 10 times, use new blah = function(); and use "blah" in replacement.
Re: switch issue -
PawnoQ - 23.12.2011
mhh, true, sounds pretty logical
thx