Return Problem
#1

Hey!

I want this function to return a float value, but the compiler writes a warning..Here is the code:

pawn Код:
new Float:OldPos[MAX_PLAYERS][3];
pawn Код:
stock GetMovedDistance(playerid, Float:posx, Float:posy, Float:posz)
{
    if(OldPos[playerid][0] == 0 || OldPos[playerid][1] == 0 || OldPos[playerid][2] == 0)
    {
        GetPlayerPos(playerid, OldPos[playerid][0],  OldPos[playerid][1],  OldPos[playerid][2]);
        return 0;
    }
    new
        Float:TempPos[MAX_PLAYERS][3],
        Float:distance;
    TempPos[playerid][0] = floatabs(posx-OldPos[playerid][0]);
    TempPos[playerid][1] = floatabs(posy-OldPos[playerid][1]);
    TempPos[playerid][2] = floatabs(posz-OldPos[playerid][2]);
    distance = floatsqroot(floatpower(TempPos[playerid][0], 2)+floatpower(TempPos[playerid][1], 2)+floatpower(TempPos[playerid][2], 2));
    OldPos[playerid][0] = posx;
    OldPos[playerid][1] = posy;
    OldPos[playerid][2] = posz;
    return distance;//Tag Mismatch warning here
}
What's the problem?
Reply
#2

Maybe it's because you are trying to return a float, try this:

pawn Код:
stock GetMovedDistance(playerid, Float:posx, Float:posy, Float:posz, &Float:distance)
{
    if(OldPos[playerid][0] == 0 || OldPos[playerid][1] == 0 || OldPos[playerid][2] == 0)
    {
        GetPlayerPos(playerid, OldPos[playerid][0],  OldPos[playerid][1],  OldPos[playerid][2]);
        return 0;
    }
    new
        Float:TempPos[MAX_PLAYERS][3],
        Float:tmpdistance;
    TempPos[playerid][0] = floatabs(posx-OldPos[playerid][0]);
    TempPos[playerid][1] = floatabs(posy-OldPos[playerid][1]);
    TempPos[playerid][2] = floatabs(posz-OldPos[playerid][2]);
    tmpdistance = floatsqroot(floatpower(TempPos[playerid][0], 2)+floatpower(TempPos[playerid][1], 2)+floatpower(TempPos[playerid][2], 2));
    OldPos[playerid][0] = posx;
    OldPos[playerid][1] = posy;
    OldPos[playerid][2] = posz;
    distance = tmpdistance;
    return 1;//Tag Mismatch warning here
}
Then you would need to do:

pawn Код:
new Float:Distance;
GetMovedDistance(playerid, X, Y, Z, Distance);
// Then use Distance as the float.
Reply
#3

Define the stock as a float since it's returning a float.

pawn Код:
stock Float:GetMovedDistance(playerid, Float:posx, Float:posy, Float:posz)
{
    if(OldPos[playerid][0] == 0 || OldPos[playerid][1] == 0 || OldPos[playerid][2] == 0)
    {
        GetPlayerPos(playerid, OldPos[playerid][0],  OldPos[playerid][1],  OldPos[playerid][2]);
        return 0;
    }
    new
        Float:TempPos[MAX_PLAYERS][3],
        Float:distance;
    TempPos[playerid][0] = floatabs(posx-OldPos[playerid][0]);
    TempPos[playerid][1] = floatabs(posy-OldPos[playerid][1]);
    TempPos[playerid][2] = floatabs(posz-OldPos[playerid][2]);
    distance = floatsqroot(floatpower(TempPos[playerid][0], 2)+floatpower(TempPos[playerid][1], 2)+floatpower(TempPos[playerid][2], 2));
    OldPos[playerid][0] = posx;
    OldPos[playerid][1] = posy;
    OldPos[playerid][2] = posz;
    return distance;//Tag Mismatch warning here
}
Reply
#4

Ah, I was completely wrong. Probably still work though.
Reply
#5

Ahh, Thanks a Lot.

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
Define the stock as a float since it's returning a float.
Tried it first, but I didn't changed the first return to return 0.0
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)