SA-MP Forums Archive
Unreachable Code - 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: Unreachable Code (/showthread.php?tid=556476)



Unreachable Code - Ciarannn - 10.01.2015

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


Re: Unreachable Code - acade - 10.01.2015

Try this: http://pastebin.com/zsNYiyF5


Re: Unreachable Code - CalvinC - 10.01.2015

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.