SA-MP Forums Archive
Warning 225: Unreachable Code [PAWN] - 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: Warning 225: Unreachable Code [PAWN] (/showthread.php?tid=443279)



Warning 225: Unreachable Code [PAWN] (FIXED) - DarkPower010 - 11.06.2013

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;
}



Re: warning 225: unreachable code - rpg894 - 11.06.2013

if (lfdljgn;ds)
{
}


Re: Warning 225: Unreachable Code [PAWN] - DarkPower010 - 11.06.2013

i dont understand.. please edit the script


Re: Warning 225: Unreachable Code [PAWN] - rpg894 - 11.06.2013

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


Re: Warning 225: Unreachable Code [PAWN] - DarkPower010 - 11.06.2013

well can i ignore the warning?

and.. did you mean every if must have return?


AW: Re: Warning 225: Unreachable Code [PAWN] - HurtLocker - 11.06.2013

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.


Re: Warning 225: Unreachable Code [PAWN] - [ABK]Antonio - 11.06.2013

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


Re: Warning 225: Unreachable Code [PAWN] - Sascha - 11.06.2013

Код:
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;
}



Re: Warning 225: Unreachable Code [PAWN] - DarkPower010 - 11.06.2013

Thank you! for everything.


Re: Warning 225: Unreachable Code [PAWN] - Slice - 11.06.2013

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.