What exactly does 'return 1;' do and why do we need it?
#6

return means to return a value in a function or w/e

like the following example:

pawn Код:
new playernub;

public OnPlayerConnect(playerid)
{
    playernub = GetPlayerNub(playerid); // GetPlayerNub will now return rand (0 or 1 , according to the random function)

    printf("GetPlayerNub function on playerid %i result is: %i", playerid, playernub);
    return 1;
}

stock GetPlayerNub(playerid)
{
    new rand = random(1);
    return rand; // will return 1 or 0 (according to the random function)
}
it also means to stop continuing from reading the other part of the script.

like the following

pawn Код:
public OnPlayerConnect(playerid)
{
    if(IsPlayerNPC(playerid)) return 1; // checks if the player that connected is an NPC, the script will stop reading OnPlayerConnect.

    ShowPlayerLogin(playerid, login, blablabl);
    return 1;
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 5 Guest(s)