Unreachable Code
#1

I'm having a little problem. I'm getting an error, "Unreachable Code". I know why I'm getting the error, but I don't know how to write the code so I don't get the error.

So, here is the code:

Код:
	if(IsTruckerCar(vehicleid))
	    {
	    	if(PlayerInfo[playerid][pJob] != JOB_TRUCKER && PlayerInfo[playerid][pVIPJob] != JOB_TRUCKER)
				{
					SendClientMessage(playerid, COLOR_ORANGE, "You are not a Trucker.");
	    			new Float:pos[3];
				    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
				    SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
				    return 1;
				}
				else
   				{
       	    		SetPlayerCheckpoint(playerid, 325.2717,2544.1748,16.8077, 7);
       	    		SendClientMessage(playerid, COLOR_GREY, "Head to the loading bay and load up your truck.");
					return 1;
            	}

			if(!PlayerInfo[playerid][pDelivery])
				{
					SendClientMessage(playerid, COLOR_ORANGE, "You are not on a delivery.");
	    			new Float:pos[3];
				    GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
				    SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
				    return 1;
				}
	 	}
How do I write that so the second if(!PlayerInfo[playerid][pDelivery]) can be reached?

EDIT: Here it is on pastebin if the indentation is making it too hard to read: http://pastebin.com/p4YcvYHy
Reply
#2

Try this: http://pastebin.com/zsNYiyF5
Reply
#3

pawn Код:
if(IsTruckerCar(vehicleid))
        {
            if(PlayerInfo[playerid][pJob] != JOB_TRUCKER && PlayerInfo[playerid][pVIPJob] != JOB_TRUCKER)
            {
                SendClientMessage(playerid, COLOR_ORANGE, "You are not a Trucker.");
                new Float:pos[3];
                GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
            }
            else
            {
                SetPlayerCheckpoint(playerid, 325.2717,2544.1748,16.8077, 7);
                SendClientMessage(playerid, COLOR_GREY, "Head to the loading bay and load up your truck.");
            }
            if(!PlayerInfo[playerid][pDelivery])
            {
                SendClientMessage(playerid, COLOR_ORANGE, "You are not on a delivery.");
                new Float:pos[3];
                GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                SetPlayerPos(playerid, pos[0], pos[1], pos[2]);
                }
        }
        return 1;
Instead of using 2 returns in each function, use 1 in the end like above.
Otherwise you will get the unreachable code warning.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)