if-else or switch? Whats better? - 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: if-else or switch? Whats better? (
/showthread.php?tid=630241)
if-else or switch? Whats better? -
faxxe - 11.03.2017
Ahoy friends.
Im trying to do this
Код:
switch(TEAMSIZE)
{
case >=2:
{
switch(gPlayerTeamSelection[playerid])
{
case 1:
{
SetPlayerColor(playerid,COLOR_TEAM_ONE);
}
case 2:
{
SetPlayerColor(playerid,COLOR_TEAM_TWO);
}
}
}
case >=3:
{
switch(gPlayerTeamSelection[playerid])
{
case 3:
{
SetPlayerColor(playerid,COLOR_TEAM_THREE);
}
}
}
case >=4:
{
switch(gPlayerTeamSelection[playerid])
{
case 3:
{
SetPlayerColor(playerid,COLOR_TEAM_FOUR);
}
}
}
case >=5:
{
switch(gPlayerTeamSelection[playerid])
{
case 3:
{
SetPlayerColor(playerid,COLOR_TEAM_FIVE);
}
}
}
case >=6:
{
switch(gPlayerTeamSelection[playerid])
{
case 3:
{
SetPlayerColor(playerid,COLOR_TEAM_SIX);
}
}
}
Can i use >=6 in switch case or do i have to use if-else-if ? Because according to the compiler its an invalid expression
Maybe someone can help to find the best way
Re: if-else or switch? Whats better? -
Jefff - 11.03.2017
You must use case 6..max_next_value:
example
case 6..10:
Re: if-else or switch? Whats better? -
faxxe - 11.03.2017
So its better to use if-else if i want to check if something is less or equal?
Or can you give an example?
So i could use case 2..6: ?
Ah now i saw your example.. i will try