What's the diffrences between Return True and Return False
#1

Hello, Could you guys explain what is the diffrences between "Return False" and "Return Right"...
Or you if got good tutorial about that.. please
Reply
#2

Use ****** and you will find it
Reply
#3

Do you have good tutorial for me?
Reply
#4

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

Quote:
Originally Posted by davidstyle1125
Посмотреть сообщение
Hello, Could you guys explain what is the diffrences between "Return False" and "Return Right"...
Or you if got good tutorial about that.. please
To get started, there's no such thing as return right; Unless, of course, it's the name of a local variable defined in the function' scope. It's a pretty basic question of Logic programming, there's no tutorial to understand it.

Quote:
Originally Posted by Raweresh
Посмотреть сообщение
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
I'm sorry bro, but you don't know what you're talking about.

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;
}
So let's say you want to ask...

Код:
if (AreWeThereYet()) {
  // You got a thumbs up (true), you made it!
} else {
  // You got a thumbs down (false), you are not there yet!
}
Four considerations:

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


Forum Jump:


Users browsing this thread: 1 Guest(s)