Using a switch
#1

Hello, im wondering if you could use a switch for something like IsPlayerInVehicle, or IsPlayerInDynamicArea (from Incognito's streamer)
Here's a code of what i mean with IsPlayerInDynamicArea:
pawn Код:
if(IsPlayerInDynamicArea(i, LosSantos))
{
    // Codes
}
else if(IsPlayerInDynamicArea(i, SanFierro))
{
    // Codes
}
else if(IsPlayerInDynamicArea(i, LasVenturas))
{
    // Codes
}
As you can see, im using "if"'s to check each of these, and i think it would be much quicker using a switch, but im not sure how, for checking different areas?

This doesn't work, but just an example if you still don't understand.
pawn Код:
switch(IsPlayerInDynamicArea(i))
{
    case LosSantos:
    {
        // Codes
    }
    case SanFierro:
    {
        // Codes
    }
    case LasVenturas:
    {
        // Codes
    }
}
This would kinda be what i want.
Reply
#2

Unfortunately, no. The cases must be a constant value. That means that their value must be known at compile time.
Reply
#3

I read somewhere that NOT using switch isn't bad. If you use IF ELSE statements ,for like 10 things , it won't decrease your speed , but using many WILL. Correct me if this is wrong
Reply
#4

Quote:
Originally Posted by Sime30
Посмотреть сообщение
I read somewhere that NOT using switch isn't bad. If you use IF ELSE statements ,for like 10 things , it won't decrease your speed , but using many WILL. Correct me if this is wrong
Im not saying it's too bad using some "else if"'s, but it would be faster if you could have used a simple switch.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)