Using a switch - 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: Using a switch (
/showthread.php?tid=560224)
Using a switch -
CalvinC - 27.01.2015
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.
Re: Using a switch -
Vince - 27.01.2015
Unfortunately, no. The cases must be a constant value. That means that their value must be known at compile time.
Re: Using a switch -
Sime30 - 27.01.2015
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
Re: Using a switch -
CalvinC - 27.01.2015
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.