Else or Else if? - 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: Else or Else if? (
/showthread.php?tid=422488)
Else or Else if? -
Blackazur - 13.03.2013
Hello, i've have an question here
there else or else if?
Код:
new Humans, Zombies, rand = random(2);
if(rand == 0)
{
foreach(Player, i)
{
if(Humans == Zombies)
{
HumanSetup2(i);
Humans ++;
}
else
{
ZombieSetup2(playerid);
Zombies ++;
}
}
}
else if(rand == 0) // Here else or else if?
{
foreach(Player, i)
{
if(Humans == Zombies)
{
ZombieSetup2(i);
Zombies ++;
}
else
{
HumanSetup2(i);
Humans ++;
}
}
}
Re: Else or Else if? -
Misiur - 13.03.2013
This makes no sense, as you already covered it with if statement. If you want to compare against 1, normal else will suffice. Also !rand is equal rand == 0
AW: Else or Else if? -
Blackazur - 13.03.2013
Also just "else"?
Re: Else or Else if? -
Pottus - 13.03.2013
Like this.....
r = random(2);
if(r == 0) { }
else { } // r = 1
use elseif when.....
r = random(3);
if(r == 0) {}
else if(r == 1) {}
else {} // r = 2
Re: Else or Else if? -
Misiur - 13.03.2013
pawn Код:
new Humans, Zombies, rand = random(2);
foreach(Player, i)
{
if(rand && Humans == Zombies)
{
ZombieSetup2(i);
Zombies ++;
}
else
{
HumanSetup2(i);
Humans ++;
}
}
AW: Else or Else if? -
Blackazur - 13.03.2013
Thanks! And that is right, or?
Код:
stock Half()
{
new Humans;
foreach(Player, i)
{
if(Humans < 3)
{
HumanSetup(i);
Humans ++;
}
else
{
ZombieSetup2(i);
Humans = 0;
}
}
return 1;
}
Re: Else or Else if? -
Misiur - 13.03.2013
If its task is to create 2 humans per zombie, then looks fine to me.
Re: Else or Else if? -
mastermax7777 - 13.03.2013
https://sampwiki.blast.hk/wiki/Control_Structures#else