SA-MP Forums Archive
case help - 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: case help (/showthread.php?tid=401915)



case help - arko123 - 24.12.2012

errors:

pawn Код:
Arko.pwn(27341) : error 036: empty statement
Arko.pwn(27344) : error 002: only a single statement (or expression) can follow each "case"
Arko.pwn(27344 -- 27345) : error 029: invalid expression, assumed zero
Arko.pwn(27346) : error 014: invalid statement; not in switch
Arko.pwn(27346) : warning 215: expression has no effect
Arko.pwn(27346) : error 001: expected token: ";", but found ":"
Arko.pwn(27346) : error 029: invalid expression, assumed zero
Arko.pwn(27346) : fatal error 107: too many error messages on one line
Code:

pawn Код:
command(seatbelt, playerid, params[])
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new string[128], vehicleid = GetPlayerVehicleID(playerid);;
            switch(Player[playerid][Seatbelt])
            {
                if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510)
                {
                    case 0:
                    {
                    Player[playerid][Seatbelt] = 1;
                    format(string, sizeof(string), "* %s take their helmet placing it on their head, straping it tightly.", GetName(playerid));
                    NearByMessage(playerid, PURPLE, string);
                    }
                    case 1:
                    {
                    Player[playerid][Seatbelt] = 0;
                    format(string, sizeof(string), "* %s unstraps their helmet, taking it off.", GetName(playerid));
                    NearByMessage(playerid, PURPLE, string);
                    }
                {
                else
                }
                switch(Player[playerid][Seatbelt])
                {
                    case 0:
                    {
                    Player[playerid][Seatbelt] = 1;
                    format(string, sizeof(string), "* %s slides their seatbelt across their chest, buckling it tightly", GetName(playerid));
                    NearByMessage(playerid, PURPLE, string);
                    }
                    case 1:
                    {
                    Player[playerid][Seatbelt] = 0;
                    format(string, sizeof(string), "* %s unbuckles their seatbelt", GetName(playerid));
                    NearByMessage(playerid, PURPLE, string);
                }
            }
        }
    }
    return 1;
}



Re: case help - NighelN - 24.12.2012

The else is your problem change it to this

pawn Код:
command(seatbelt, playerid, params[])
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new string[128], vehicleid = GetPlayerVehicleID(playerid);;
            switch(Player[playerid][Seatbelt])
            {
                if(GetVehicleModel(vehicleid) == 481 || GetVehicleModel(vehicleid) == 509 || GetVehicleModel(vehicleid) == 510) {
                    case 0: {
                        Player[playerid][Seatbelt] = 1;
                        format(string, sizeof(string), "* %s take their helmet placing it on their head, straping it tightly.", GetName(playerid));
                        NearByMessage(playerid, PURPLE, string);
                    }
                    case 1: {
                        Player[playerid][Seatbelt] = 0;
                        format(string, sizeof(string), "* %s unstraps their helmet, taking it off.", GetName(playerid));
                        NearByMessage(playerid, PURPLE, string);
                    }
                } else {
                switch(Player[playerid][Seatbelt])
                {
                    case 0:
                    {
                    Player[playerid][Seatbelt] = 1;
                    format(string, sizeof(string), "* %s slides their seatbelt across their chest, buckling it tightly", GetName(playerid));
                    NearByMessage(playerid, PURPLE, string);
                    }
                    case 1:
                    {
                    Player[playerid][Seatbelt] = 0;
                    format(string, sizeof(string), "* %s unbuckles their seatbelt", GetName(playerid));
                    NearByMessage(playerid, PURPLE, string);
                }
            }
        }
    }
    return 1;
}



Re: case help - Vince - 24.12.2012

Only case statements may appear within a switch statement, but if-statements may appear within a case statement. If that made sense.


Re: case help - arko123 - 24.12.2012

Removed Message


Re: case help - arko123 - 24.12.2012

Quote:
Originally Posted by Vince
Посмотреть сообщение
Only case statements may appear within a switch statement, but if-statements may appear within a case statement. If that made sense.
Yeah I got it thanks.