How to use return 1/0 ?
#9

Quote:
Originally Posted by Abagail
View Post
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:
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate) {
     if(newstate == PLAYER_STATE_DRIVER && IsACopVehicle(GetPlayerVehicleID(playerid)) {
           if(!IsACop(playerid)) return RemovePlayerFromVehicle(playerid);
     }

     return 1;
}
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).
Thank you, but in this case is absolutely necessary?

Code:
if(listitem == 0) 
{ 
    if(PlayerData[playerid][pLocateCar] == 1) 
    { 
        format(szMessage,sizeof szMessage,"Your car (Model: %s) has been respawned!",VehicleNames[PlayerData[playerid][pCarModel1]-400]); 
        SendClientMessage(playerid,COLOR_WHITE,szMessage); 
        return 1; 
    } 
}
Reply


Messages In This Thread
How to use return 1/0 ? - by Nin9r - 27.07.2015, 21:50
AW: How to use return 1/0 ? - by Mencent - 27.07.2015, 21:56
Re: How to use return 1/0 ? - by Rodri99 - 27.07.2015, 21:57
Re: AW: How to use return 1/0 ? - by Nin9r - 27.07.2015, 21:59
Re: How to use return 1/0 ? - by TenTen - 27.07.2015, 22:00
Re: How to use return 1/0 ? - by Nin9r - 27.07.2015, 22:03
Re: How to use return 1/0 ? - by Abagail - 27.07.2015, 22:05
AW: How to use return 1/0 ? - by Mencent - 27.07.2015, 22:07
Re: How to use return 1/0 ? - by Nin9r - 27.07.2015, 22:10
Re: How to use return 1/0 ? - by !damo!spiderman - 27.07.2015, 22:13

Forum Jump:


Users browsing this thread: 2 Guest(s)