warning 209: function "NearATrunk" should return a value
#1

The Error:
PHP код:
warning 209: function "NearATrunk" should return a value
My Code:
PHP код:
stock bool:NearATrunk(PlayerID, &TheVehicleID)
{
    for(new 
VehicleID 0VehicleID MAX_VEHICLESVehicleID++)
    {
        if(
IsValidVehicle(VehicleID))
        {
            new 
Float:VehicleCoordinates[3];
            
GetVehiclePos(VehicleIDVehicleCoordinates[0], VehicleCoordinates[1], VehicleCoordinates[2]);
            
VehicleCoordinates[1] -= 2.865000;
            
VehicleCoordinates[2] -= 0.159999;
            if(
GetPlayerDistanceFromPoint(PlayerIDVehicleCoordinates[0], VehicleCoordinates[1], VehicleCoordinates[2]) <= 3)
            {
                
TheVehicleID VehicleID;
                return 
true;
            }
            else
            {
                
TheVehicleID INVALID_VEHICLE_ID;
                return 
false;
            }
        }
        else
        {
            
TheVehicleID INVALID_VEHICLE_ID;
            return 
false;
        }
    }

Reply
#2

You just have to return a true/false (which will never be reached unless the loop fails) outta (below) the For loop.
Reply
#3

pawn Код:
stock bool:NearATrunk(PlayerID, &TheVehicleID)
{
    for(new VehicleID = 0; VehicleID < MAX_VEHICLES; VehicleID++)
    {
        if(IsValidVehicle(VehicleID))
        {
            new Float:VehicleCoordinates[3];
            GetVehiclePos(VehicleID, VehicleCoordinates[0], VehicleCoordinates[1], VehicleCoordinates[2]);
            VehicleCoordinates[1] -= 2.865000;
            VehicleCoordinates[2] -= 0.159999;
            if(GetPlayerDistanceFromPoint(PlayerID, VehicleCoordinates[0], VehicleCoordinates[1], VehicleCoordinates[2]) <= 3)
            {
                TheVehicleID = VehicleID;
                return true;
            }
            else
            {
                TheVehicleID = INVALID_VEHICLE_ID;
                return false;
            }
        }
        else
        {
            TheVehicleID = INVALID_VEHICLE_ID;
            return false;
        }
    }
   return 1;
}
Reply
#4

now i get "tag mismatch" at the "return 1;"
Reply
#5

Change the "return 1;" into "return false;".
Reply
#6

2 useless else statements removed also you have to do it this way because the way you had it would only do one iteration.

pawn Код:
stock bool:NearATrunk(PlayerID, &TheVehicleID)
{
    for(new VehicleID = 0; VehicleID < MAX_VEHICLES; VehicleID++)
    {
        if(IsValidVehicle(VehicleID))
        {
            new Float:VehicleCoordinates[3];
            GetVehiclePos(VehicleID, VehicleCoordinates[0], VehicleCoordinates[1], VehicleCoordinates[2]);
            VehicleCoordinates[1] -= 2.865000;
            VehicleCoordinates[2] -= 0.159999;
            if(GetPlayerDistanceFromPoint(PlayerID, VehicleCoordinates[0], VehicleCoordinates[1], VehicleCoordinates[2]) <= 3)
            {
                TheVehicleID = VehicleID;
                return true;
            }
        }
    }
    TheVehicleID = INVALID_VEHICLE_ID;
    return false;
}
Reply
#7

You have a loop that will return either true or false in the very first iteration. It doesn't matter about all the other problems until you fix that. Basically, if you aren't near the first vehicle, it will never work because none of the others will be tested - the function has ended.

Edit: Fixed by [uL]Pottus' code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)