switch issue
#1

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.
Reply
#2

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?
Reply
#3

100% sure as i commented this code and without this part of code it worked like a charm
Reply
#4

switch statements don't work with very large values, that's what ******'s is trying to say. I had a very similiar problem.
Reply
#5

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
Reply
#6

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.
Reply
#7

mhh, true, sounds pretty logical

thx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)