SA-MP Forums Archive
changing if else to switch(...) case - 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: changing if else to switch(...) case (/showthread.php?tid=593252)



changing if else to switch(...) case - xTURBOx - 03.11.2015

PHP код:
if(pInfo[playerid][Adminlevel] == 1)
                {
                    
GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 1 ~g~~n~(Trial moderator) ",3000,3);
                }
                else if(
pInfo[playerid][Adminlevel] == 2)
                {
                    
GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 2 ~g~~n~(Moderator) ",3000,3);
                }
                else if(
pInfo[playerid][Adminlevel] == 3)
                {
                    
GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 3 ~g~~n~(Junior Administrator) ",3000,3);
                }
                else if(
pInfo[playerid][Adminlevel] == 4)
                {
                    
GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 4 ~g~~n~(Senior Administrator) ",3000,3);
                }
                else if(
pInfo[playerid][Adminlevel] == 5)
                {
                    
GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 5 ~g~~n~(Master Administrator) ",3000,3);
                }
                else if(
pInfo[playerid][Adminlevel] == 6)
                {
                    
GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 6 ~g~~n~(Server Owner) ",3000,3);
                }
                else
                {
                    
GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in",3000,3);
                } 
How do i write the code above using
PHP код:
switch()
{
case 
0:
case 
1:
and 
so on




Re: changing if else to switch(...) case - HydraHumza - 03.11.2015

Код:
		switch(pInfo[playerid][Adminlevel])
		{
			case 0:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in!) ",3000,3);
	                }
			case 1:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 1 ~g~~n~(Trial moderator) ",3000,3);
	                }
	                case 2:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 2 ~g~~n~(Moderator) ",3000,3);
	                }
	                case 3:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 3 ~g~~n~(Junior Administrator) ",3000,3);
	                }
	                case 4:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 4 ~g~~n~(Senior Administrator) ",3000,3);
	                }
	                case 5:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 5 ~g~~n~(Master Administrator) ",3000,3);
	                }
	                case 6:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 6 ~g~~n~(Server Owner) ",3000,3);
	                }
		}
You mean this?


Re: changing if else to switch(...) case - xTURBOx - 03.11.2015

Quote:
Originally Posted by Humza
Посмотреть сообщение
Код:
		switch(pInfo[playerid][Adminlevel])
		{
			case 0:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in!) ",3000,3);
	                }
			case 1:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 1 ~g~~n~(Trial moderator) ",3000,3);
	                }
	                case 2:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 2 ~g~~n~(Moderator) ",3000,3);
	                }
	                case 3:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 3 ~g~~n~(Junior Administrator) ",3000,3);
	                }
	                case 4:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 4 ~g~~n~(Senior Administrator) ",3000,3);
	                }
	                case 5:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 5 ~g~~n~(Master Administrator) ",3000,3);
	                }
	                case 6:
	                {
	                    GameTextForPlayer(playerid,"~b~Welcome!~w~ Logged in~n~ Adminlevel 6 ~g~~n~(Server Owner) ",3000,3);
	                }
		}
You mean this?
yeah thanks