24.05.2016, 09:55
Hello. What's the difference between else and else if ?
How to use?
How to use?
if (goto school) { get knowledge } else { not get any }
if (goto school) { get knowledge } else if (goto mall) { shoping } else if(goto movies) { get a girlfriend :D } else { not get any }
CMD:god(playerid,params[])
{
if(PlayerInfo[playerid][pAdminlvl] >= 4 && PlayerGodMode[playerid] == 1) // If the player has AT LEAST a admin lvl > 4 AND he is NOT in godmode
{
PlayerGodMode[playerid] = 2;
SendClientMessage(playerid, -1, "Godmode on");
GOD = SetTimerEx("GodMode", 100, true, "i", playerid);
return 1;
}
else if(PlayerInfo[playerid][pAdminlvl] >= 4 && PlayerGodMode[playerid] == 2) // ELSE IF the player has AT LEAST a admin lvl > 4 AND he IS in godmode.
{
SendClientMessage(playerid, -1, "Godmode off");
KillTimer(GOD);
PlayerGodMode[playerid] = 1;
SetPlayerHealth(playerid, 100.0);
SetPlayerArmour(playerid, 100.0);
return 1;
}
else return SendClientMessage(playerid, red, "You are not allowed to use this command."); // ELSE : the player isn't admin
}
For the first: both if statements are checked.
For the second: the else if statement will be checked only if the if statement is false. That means that if the if statement is true, the else if will never be checked. |
if(var == 1)
{
}
else if(var == 2)
{
}
else if(var == 3)
{
}
switch(var)
{
case 1:
{
// This is if(var == 1)
}
case 2:
{
// This is if(var == 2)
}
case 3:
{
// This is if(var == 3)
}
default:
{
// This is else
}
}
So, the script will return when the if value is true?
new var = 2; if(var == 1) { } else if(var == 2) { } else if(var == 3) { } . The script will be returned at if var == 2 no ? if { } if { } will be used just if you want to check different values in any script. I understand now. Thank you. |
if(GetPlayerWeapon(playerid) == 4) // if player has a Knife it will Send player a message " This is a Knife" { SendClientMessage(playerid, -1, "This Is A Knife."); } else if(GetPlayerWeapon(playerid) == 5) // but if player has a Baseball Bat it will Send player a message " This is a BaseBall bat." { SendClientMessage(playerid, -1, "This is A BaseBall Bat."); }