PDA

View Full Version : Using a switch


CalvinC
27/01/2015, 04:20 PM
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:
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.
switch(IsPlayerInDynamicArea(i))
{
case LosSantos:
{
// Codes
}
case SanFierro:
{
// Codes
}
case LasVenturas:
{
// Codes
}
}
This would kinda be what i want.

Vince
27/01/2015, 04:41 PM
Unfortunately, no. The cases must be a constant value. That means that their value must be known at compile time.

Sime30
27/01/2015, 04:50 PM
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

CalvinC
27/01/2015, 05:06 PM
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.