SA-MP Forums Archive
switch() questions - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: switch() questions (/showthread.php?tid=257189)



switch() questions - Blt950 - 24.05.2011

Hello,

I got a question about the switch() function.

Here is an example:

pawn Код:
switch(reason)
        {
            case 0:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Crashed)",playerid, pName);
            }
            case 1:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Leaving)",playerid, pName);
            }
            case 2:
            {
                format(string, sizeof(string),"[%d] %s has left the server. (Kicked/Banned)",playerid, pName);
            }
        }
Is there any reason to add a "else" inside this switch or something?
Any ideas?

Thanks


Re: switch() questions - DeathOnaStick - 24.05.2011

Quote:
Originally Posted by Blt950
Посмотреть сообщение
Hello,

I got a question about the switch() function.

Here is an example:

pawn Код:
switch(reason)
        {
            case 0:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Crashed)",playerid, pName);
            }
            case 1:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Leaving)",playerid, pName);
            }
            case 2:
            {
                format(string, sizeof(string),"[%d] %s has left the server. (Kicked/Banned)",playerid, pName);
            }
        }
Is there any reason to add a "else" inside this switch or something?
Any ideas?

Thanks
pawn Код:
switch(reason)
        {
            case 0:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Crashed)",playerid, pName);
            }
            case 1:
            {
                format(string, sizeof(string), "[%d] %s has left the server. (Leaving)",playerid, pName);
            }
            case 2:
            {
                format(string, sizeof(string),"[%d] %s has left the server. (Kicked/Banned)",playerid, pName);
            }
            default:
            {
                //The else thingy
            }
        }



Re: switch() questions - Seven_of_Nine - 24.05.2011

Use default:
pawn Код:
case humm: format(humm);
default: //This is the else part.



Re: switch() questions - Blt950 - 24.05.2011

Ah, of course!

Thanks a lot