09.12.2014, 20:34
Quote:
Hello, Could you guys explain what is the diffrences between "Return False" and "Return Right"...
Or you if got good tutorial about that.. please |
Quote:
There is no differences... You can return value, true or false or nothing if you don't need.
https://sampwiki.blast.hk/wiki/Control_Structures#return |

To explain that you have to know what is booleans and functions.
A boolean is a type of variable that you define that has only two states: on or off (true or false),
and a function is a block of code that can be repeated as long as you need, every function has to return a value that can be: integer, strings, booleans, etc...
So let's say that you're travelling and you want to ask: are we there yet? That's the question that you usually doesn't ask one time only right? So you ask, are we there yet? The driver answer with a thumbs down, some time later, you ask again, are we there yet? Another thumbs down. Some time later, you ask again and the driver answer with a thumbs up, meaning yes.
In programming languages, that's pretty much how things works, you ask questions, establishes scenarios and the only answer you get is yes or not, so transcribing the scenario above to Pawn language, it would be like so:
Код:
new Bool:areWeThereYet = false; // Create a variable of type boolean and set it to false. // Create a function AreWeThereYet() { return Bool:areWeThere ; // For now, the same of: return false; }
Код:
if (AreWeThereYet()) { // You got a thumbs up (true), you made it! } else { // You got a thumbs down (false), you are not there yet! }
return true and return 1 are the same, and
return false and return 0 are the same too, and
as soon as you return something from a function, it is done, meaning that all other code
will not be reached and you can't return twice from the same function, and
is almost all programming languages every function has to return a value.
So, in SA-MP scripting we see a lot of things like that, let's take example the OnPlayerCommandText() callback that has its return handled by the server.
If you return 0 or return false from there, you're telling the server that the user entered a invalid command, if you return 1 or return true you're telling that the command exists, right?
I hope you got it, best regards.