SA-MP Forums Archive
warning 209: function "NearATrunk" should return a value - 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 209: function "NearATrunk" should return a value (/showthread.php?tid=493879)



warning 209: function "NearATrunk" should return a value - S0n1COwnsYou - 10.02.2014

The Error:
PHP код:
warning 209: function "NearATrunk" should return a value. 
My Code:
PHP код:
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;
        }
    }
} 



Re: warning 209: function "NearATrunk" should return a value - [KHK]Khalid - 10.02.2014

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


Re: warning 209: function "NearATrunk" should return a value - Vanter - 10.02.2014

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



Re: warning 209: function "NearATrunk" should return a value - S0n1COwnsYou - 10.02.2014

now i get "tag mismatch" at the "return 1;"


Re: warning 209: function "NearATrunk" should return a value - PowerPC603 - 10.02.2014

Change the "return 1;" into "return false;".


Re: warning 209: function "NearATrunk" should return a value - Pottus - 10.02.2014

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



Re: warning 209: function "NearATrunk" should return a value - ColeMiner - 10.02.2014

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.