switch
#1

I have this command:

pawn Код:
CMD:test(playerid, params[])
{
    new location;
    if(sscanf(params, "i", location))return SendClientMessage(playerid, -1, "Usage: /test [location]");
Can i do in this command something like this:

pawn Код:
CMD:test(playerid, params[])
{
    new location;
    if(sscanf(params, "i", location))return SendClientMessage(playerid, -1, "Usage: /test [location]");
    switch(location)
    {
        case 0:
        {
            SetPlayerPos(playerid, x,y,z);
        }
        case 1:
        {
            SetPlayerPos(playerid, x,y,z);
        }
        ...
        case 5:
        {
            SetPlayerPos(playerid, x,y,z);
        }
        return 1;
}
Is this coretly and is this gonna work?
Reply
#2

EDIT:
you got your answer
Reply
#3

x,y,z => is coordinat and I didnt publish coordinat i type x,y,z it is easier to explain i will add it leater i dont have this command but i want to do something close to that so i ask is this a good way for "switch" or isnt...
Reply
#4

Yes, it is correct. Although I would add a little check like:

pawn Код:
if(location < 0 && location > YOURMAXIMUMAMOUNOFLOCATIONS)
that way you could send the player a message saying that he is using an incorrect idea. Just a little thing but it might be useful
Reply
#5

'switch' is faster than 'ifs' if there are more than 2 checks. So your version is fine and is probably the best way to do it.

EDIT: About the above post you can achieve that in a switch with the default case.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)