Return 0; and return 1; - 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: Return 0; and return 1; (
/showthread.php?tid=402821)
Return 0; and return 1; - XProtocol - 28.12.2012
What is the difference between return 0; and return 1; ?
Re: Return 0; and return 1; -
rockerman - 28.12.2012
Usually zero is returned to the calling function or operating system when a program was executed successfully.
Other numbers may be returned if an error occurred during the execution, and the specific number would indicate the type of error. For example, say, if an error occurred while opening a file the value returned will be 1. This also helps in debugging programs.
Re: Return 0; and return 1; - XProtocol - 28.12.2012
Oh thanks.
Re: Return 0; and return 1; -
Grim_ - 28.12.2012
Some of SA:MP's callback will behave differently when having a specific value returned. For example, OnPlayerRequestSpawn will only allow the player to spawn successfully with the current classid if 1 is returned. You can check the wiki for the specific callbacks/functions and see if it makes a difference. Generally, returning the value of 1 is standard.
Re: Return 0; and return 1; -
rockerman - 28.12.2012
no problem
Re: Return 0; and return 1; - XProtocol - 28.12.2012
So how do we know where we need to add to return 1; ?
Re: Return 0; and return 1; -
Threshold - 28.12.2012
Basically, you can think of it this way, 1 = success/true, 0 = failed/false
Examples:
pawn Код:
MyGateIsOpen = 1; //It is open
if(MyGateIsOpen == 1)
{
CloseGate;
MyGateIsOpen = 0; //It is now closed or false (without the use of booleans)
//...
pawn Код:
public OnPlayerSpawn(playerid)
{
return 1; //The player has spawned
}
public OnPlayerRequestClass(playerid, classid)
{
if(classid == 12) return 0; //Do not spawn player, player spawned with class = false
return 1; //Else let them spawn by returning 1
}
I don't know of any existing tutorials about returning values, based around 0 and 1, but keep searching if you need help with it. Or check out the SA-MP Wiki.
Re: Return 0; and return 1; -
tyler12 - 28.12.2012
https://sampwiki.blast.hk/wiki/Control_Structures#return
Re: Return 0; and return 1; - XProtocol - 28.12.2012
Thank's
Helped me