Why are there so few "return" functions with SA:MP?
#6

This is what I presume is happening inside the SAMP server when I execute GetPlayerHealth:
pawn Code:
stock GetPlayerHealth(playerid, &health)
{
    RequestUpdateFromClient(playerid);
    health = playerHealth[playerid];
}
Surely it would be just as simple to do this:
This is what I presume is happening inside the SAMP server when I execute GetPlayerHealth:
pawn Code:
stock Float:GetPlayerHealth(playerid, &health)
{
    RequestUpdateFromClient(playerid);
    return playerHealth[playerid];
}
This would be a lot more useful because then everything could be in one line.
If you want to store the value:
pawn Code:
pHealth = GetPlayerHealth(playerid);
If you want to use the value:
pawn Code:
format(string, sizeof(string), "Your health is: %f", GetPlayerHealth(playerid));
I just really can't see why it was programmed the other way.

Quote:
Originally Posted by Vince
View Post
Despite what the wiki might say, most functions do also have a return value. Most of them return 1 on success and 0 on failure (i.e. not connected or invalid vehicleid). GetPlayerHealth is no exception. This means that doing something like this (common practice) is redundant;
I know that most functions either return 0 or 1 to indicate the success of the action but they could easily just return -1 in the event of a failure, 0 to indicate that the player is dead and otherwise return their health.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)