27.07.2015, 22:05
Returning a value is usually optional (though it will usually give a warning), though it can be useful and or needed in some situations. When simply responding to a callback typically returning 1 would be practical unless the callback does different things(such as a OnTakeDamage function not giving damage if 0 is returned) when other things are returned.
Though for functions returns can sometimes be useful & or needed. For example:
In this case, IsACop and IsACopVehicle return different values. This allows you to check if(if it returns 1) the player is a cop and if it returns 0 the player isn't a cop.
Also 1/0 aren't the only values you can return. You can return strings, and other integer values as well. NOTE: Due to an issue with the compiler directly returning a string will crash the compiler(e.g: return "yes". This works in old compiler versions and also if you're using Zeex's compiler patches(I believe).
Though for functions returns can sometimes be useful & or needed. For example:
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate) {
if(newstate == PLAYER_STATE_DRIVER && IsACopVehicle(GetPlayerVehicleID(playerid)) {
if(!IsACop(playerid)) return RemovePlayerFromVehicle(playerid);
}
return 1;
}
Also 1/0 aren't the only values you can return. You can return strings, and other integer values as well. NOTE: Due to an issue with the compiler directly returning a string will crash the compiler(e.g: return "yes". This works in old compiler versions and also if you're using Zeex's compiler patches(I believe).