Explain returns
#1

Hello, could someone explain me how do returns work and when they are used? Right now I just put them randomly and sometimes that causes stuff below the code to stop working and I randomly fix it by removing it or adding it or changing a place and I have no idea why. :P
Reply
#2

Returns are used at the end of a piece of code to return whether or not the executed coding was successful or not, you can use this to cut code short such as checking if someone's an admin in a command or many other things. This means when the command is calledm, if a return is used, the command will return that value and then stop and will not perform the rest of the code in that section.

pawn Код:
CMD:test(playerid, params[])
{
     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You are not an admin");
    //rest of code which will not be executed if player is not an admin
}
Reply
#3

returns are also used to return values in any function or code!

Like CreateVehicle returns the vehicle id of the vehicle just created , same with many callbacks!
Like GetPlayerVehicleID returns vehicle id which player is driving!

You can make custom callbacks tu return many kind of values and more functions also!

Functions can also return functions! returns can also be used to return true or false in a function!
Reply
#4

So for example I make a GUI list which has 3 options. Should I put a return after each option so the code wouldn't be read further? This would same some bandwitch right?
Reply
#5

Exactly. return 1 is used for it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)