Warning 225: Unreachable Code.
#1

Howdy ya'll, I think you all know me already since I posted many threads in need of help, so heres another problem I have!

Whenever the pawn program scans for any errors, it says that line 10800 (Marked in red below) has a warnin'. Anyone have an idea why it says that?

Warning Line: if(IsPlayerInRangeOfPoint(playerid, 5, -1581.7371,-1609.9010,36.5233)) // Toll Barrier

Warning Error: C:\Users\Krakuski!\Desktop\Angel Pine Roleplay\gamemodes\BETA_TEST_SERVER.pwn(10800) : warning 225: unreachable code
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Warning.



Code:
CMD:paytoll(playerid, params[])
{
	new string[128];
 	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
	if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You are not driving a vehicle.");
	if(PlayerInfo[playerid][pMoney] < 1400) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough money to pay the toll ($1400)!");
	{
	    SendClientMessage(playerid, COLOR_GREY, "You are not near a toll booth!");
	    return 1;
	}
 	if(IsPlayerInRangeOfPoint(playerid, 5, -1581.7371,-1609.9010,36.5233)) // Toll Barrier
	{
	    if(!TollGateStatus)
	    {
	        TollGateStatus = 1;
	        MoveDynamicObject(TollGate, -1577.1992188,-1606.6992188,36.7999992,0.0000000,270.0000000,97.9979248, 2);
	    }
	    else
	    {
	        TollGateStatus = 0;
	        MoveDynamicObject(TollGate, -1577.1999512,-1606.6999512,36.7999992,0.0000000,336.7500000,98.0000000, 2);
	    }
	    return 1;
	}
	GiveZaiatMoney(playerid, -1400);
	if(Fuel[GetPlayerVehicleID(playerid)] <= 25) return SendClientMessage(playerid, COLOR_GREY, "Your vehicle's fuel tank is too low to pay the toll!");
    format(string, sizeof(string), "* %s takes out $1400 from their wallet and hands it to the toll booth manager", RPN(playerid));
	SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
	return 1;
}
Reply
#2

pawn Code:
else
        {
            TollGateStatus = 0;
            MoveDynamicObject(TollGate, -1577.1999512,-1606.6999512,36.7999992,0.0000000,336.7500000,98.0000000, 2);
        }
        return 1; // REMOVE THIS
You made an if and a else, then there's no way that the machine reaches that return 1 because it's gonna fall in the if or in the else always.
Reply
#3

Alright, Mind if you can give me the full command?
Reply
#4

It's not hard to remove that line :L

pawn Code:
CMD:paytoll(playerid, params[])
{
    new string[128];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You are not driving a vehicle.");
    if(PlayerInfo[playerid][pMoney] < 1400) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough money to pay the toll ($1400)!");
    {
        SendClientMessage(playerid, COLOR_GREY, "You are not near a toll booth!");
        return 1;
    }
    if(IsPlayerInRangeOfPoint(playerid, 5, -1581.7371,-1609.9010,36.5233)) // Toll Barrier
    {
        if(!TollGateStatus)
        {
            TollGateStatus = 1;
            MoveDynamicObject(TollGate, -1577.1992188,-1606.6992188,36.7999992,0.0000000,270.0000000,97.9979248, 2);
        }
        else
        {
            TollGateStatus = 0;
            MoveDynamicObject(TollGate, -1577.1999512,-1606.6999512,36.7999992,0.0000000,336.7500000,98.0000000, 2);
        }
    }
    GiveZaiatMoney(playerid, -1400);
    if(Fuel[GetPlayerVehicleID(playerid)] <= 25) return SendClientMessage(playerid, COLOR_GREY, "Your vehicle's fuel tank is too low to pay the toll!");
    format(string, sizeof(string), "* %s takes out $1400 from their wallet and hands it to the toll booth manager", RPN(playerid));
    SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    return 1;
}
Reply
#5

Im extremely sorry, but that doesnt seem to work either, anything else that you guys maybe missed?
Reply
#6

This
pawn Code:
if(PlayerInfo[playerid][pMoney] < 1400) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough money to pay the toll ($1400)!");
    {
        SendClientMessage(playerid, COLOR_GREY, "You are not near a toll booth!");
        return 1;
    }
Why make a return and then open the function? Remove the return like this
pawn Code:
if(PlayerInfo[playerid][pMoney] < 1400)
    {
        SendClientMessage(playerid, COLOR_GREY, "You are not near a toll booth!");
        return 1;
    }
Reply
#7

Well the script was returning an error that tells you it was not reaching this code:
pawn Code:
if(IsPlayerInRangeOfPoint(playerid, 5, -1581.7371,-1609.9010,36.5233)) // Toll Barrier
So obviously, the error would have to be above this line.
Basically with these few lines:
pawn Code:
if(PlayerInfo[playerid][pMoney] < 1400) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough money to pay the toll ($1400)!");
    {
        SendClientMessage(playerid, COLOR_GREY, "You are not near a toll booth!");
        return 1;
    }
You are saying, if they don't have enough money, send "You don't have enough money to pay the toll ($1400)!". However, if they DO have enough money, send "You are not near a toll booth!".

It was just a simple misunderstanding of which function goes where. You have to really think about what you're coding while you're coding it.

pawn Code:
CMD:paytoll(playerid, params[])
{
    new string[128];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You are not driving a vehicle.");
    if(PlayerInfo[playerid][pMoney] < 1400) return SendClientMessage(playerid, COLOR_GREY, "You don't have enough money to pay the toll ($1400)!");
    if(IsPlayerInRangeOfPoint(playerid, 5, -1581.7371,-1609.9010,36.5233)) // Toll Barrier
    {
        if(!TollGateStatus)
        {
            TollGateStatus = 1;
            MoveDynamicObject(TollGate, -1577.1992188,-1606.6992188,36.7999992,0.0000000,270.0000000,97.9979248, 2);
        }
        else
        {
            TollGateStatus = 0;
            MoveDynamicObject(TollGate, -1577.1999512,-1606.6999512,36.7999992,0.0000000,336.7500000,98.0000000, 2);
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_GREY, "You are not near a toll booth!");
        return 1;
    }
    GiveZaiatMoney(playerid, -1400);
    if(Fuel[GetPlayerVehicleID(playerid)] <= 25) return SendClientMessage(playerid, COLOR_GREY, "Your vehicle's fuel tank is too low to pay the toll!");
    format(string, sizeof(string), "* %s takes out $1400 from their wallet and hands it to the toll booth manager", RPN(playerid));
    SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    return 1;
}
And this bit was just weird, but whatever... 0_o
"Your vehicle's fuel tank is too low to pay the toll!"

EDIT:
NOTE: On these lines:
pawn Code:
if(!TollGateStatus)
        {
            TollGateStatus = 1;
            MoveDynamicObject(TollGate, -1577.1992188,-1606.6992188,36.7999992,0.0000000,270.0000000,97.9979248, 2);
        }
        else
        {
            TollGateStatus = 0;
            MoveDynamicObject(TollGate, -1577.1999512,-1606.6999512,36.7999992,0.0000000,336.7500000,98.0000000, 2);
        }
You are basically saying, if the gate is open, you have to pay $1400 to close it?
I would set a timer, or detect whether the player has gone through the gate, and then close it. Just a suggestion.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)