Return 0; and return 1;
#1

What is the difference between return 0; and return 1; ?
Reply
#2

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.
Reply
#3

Oh thanks.
Reply
#4

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.
Reply
#5

no problem
Reply
#6

So how do we know where we need to add to return 1; ?
Reply
#7

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.
Reply
#8

https://sampwiki.blast.hk/wiki/Control_Structures#return
Reply
#9

Thank's
Helped me
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)