Warning 225: Unreachable Code [PAWN]
#1

Please Help Me!

pawn Код:
CMD:handsup(playerid, params[])
{
    if(GetPlayerState(playerid) != 1 && GetPlayerState(playerid) != 2 && GetPlayerState(playerid) != 3 && GetPlayerState(playerid) != 7)
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_RED, "[Error]: You cannot use animations while in the vehicle!");
    return SendClientMessage(playerid, COLOR_RED, "[Spawned]: You must be spawned, To use this command!");
    if(pInfo[playerid][Freeze] == 1) return SendClientMessage(playerid, COLOR_RED, "[Error]: You are frozen, Cannot use this command!");
    SetPlayerSpecialAction(playerid,SPECIAL_ACTION_HANDSUP);
    SendAdminCMD(playerid, "handsup");
    return 1;
}
Reply
#2

if (lfdljgn;ds)
{
}
Reply
#3

i dont understand.. please edit the script
Reply
#4

Every "if" must be followed either by "return" or by { }. Your 1st if has neither of them.
Reply
#5

well can i ignore the warning?

and.. did you mean every if must have return?
Reply
#6

Quote:
Originally Posted by rpg894
Посмотреть сообщение
Every "if" must be followed either by "return" or by { }. Your 1st if has neither of them.
I think he was pretty clear about that.
Reply
#7

Quote:
Originally Posted by rpg894
Посмотреть сообщение
Every "if" must be followed either by "return" or by { }. Your 1st if has neither of them.
If statements only need { if they're more than 1 line. They don't need a return, as long as they're only one line.

pawn Код:
//If it's only one function
if(Something) ThisOneFunction();
if(Something)
    ThisOneFunction();


//If it's more than one
if(Something)
{
    ThisOneFunction();
    ThisOtherFunction();
}
if(Something) {
    ThisOneFunction();
    ThisOtherFunction();
}
if(Something) { ThisOneFunction(); ThisOtherFunction(); }
All of those are valid ways to do it
Reply
#8

Код:
CMD:handsup(playerid, params[])
{
	if(GetPlayerState(playerid) != 1 && GetPlayerState(playerid) != 2 && GetPlayerState(playerid) != 3 && GetPlayerState(playerid) != 7)
	{
		if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SendClientMessage(playerid, COLOR_RED, "[Error]: You cannot use animations while in the vehicle!");
		return SendClientMessage(playerid, COLOR_RED, "[Spawned]: You must be spawned, To use this command!");
	}
	if(pInfo[playerid][Freeze] == 1) return SendClientMessage(playerid, COLOR_RED, "[Error]: You are frozen, Cannot use this command!");
	SetPlayerSpecialAction(playerid,SPECIAL_ACTION_HANDSUP);
	SendAdminCMD(playerid, "handsup");
	return 1;
}
Reply
#9

Thank you! for everything.
Reply
#10

This is the exact same code:

pawn Код:
CMD:handsup(playerid, params[])
{
    if (GetPlayerState(playerid) != 1 && GetPlayerState(playerid) != 2 && GetPlayerState(playerid) != 3 && GetPlayerState(playerid) != 7)
    {
        if (GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
        {
            return SendClientMessage(playerid, COLOR_RED, "[Error]: You cannot use animations while in the vehicle!");
        }
    }
   
    return SendClientMessage(playerid, COLOR_RED, "[Spawned]: You must be spawned, To use this command!");
   
    if (pInfo[playerid][Freeze] == 1)
    {
        return SendClientMessage(playerid, COLOR_RED, "[Error]: You are frozen, Cannot use this command!");
    }
   
    SetPlayerSpecialAction(playerid,SPECIAL_ACTION_HANDSUP);
    SendAdminCMD(playerid, "handsup");
   
    return 1;
}
Do you see it now?
Your code will always do the return statement in the middle, which means the code below can never be reached (hence "unreachable").


So please, please, just INDENT YOUR CODE AND USE BRACES.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)