What's the difference between these ?
#1

Hey guys, does this make any sense ? or it all do the same job!

pawn Код:
if(Some Code) return Something;
pawn Код:
if(Some Code)
{
    Something;
}
pawn Код:
if(Some Code)
{
    Something;
    return 1;
}
Reply
#2

The first will return "Something"
The second will work without returning anything
The last will return alway 1
Reply
#3

Basically does the same I guess
Except the middle one?
Reply
#4

No the same. Let's say "Something" is a function. First snippet requires it to return a value - and that value will be returned by your function. The second one doesn't finish code execution, so when you have code after that "if" it will execute. Won't when using #1 and #3. The third one calls the function (it doesn't have to return any value), and returns constant number 1.
Reply
#5

The function always has to return something, the standard is 1.. you could check it, and if is doesn't work you can return 0..
Reply
#6

Not the same, you can use the first one to return a value like on forwarded function, that value that you will use in something.
And the second is like the first one, but its mission is to end public finction like OnPlayerText(...), if you put return 1: player's message is appear if you put 0, the message will not be shown.

Shotly all return code are the same because their objectif is to return a value if that function is called.

If you have a problem on your scripts put it and we will help you because your question is indirect !
Reply
#7

I have to say that, while they are all different, and work differently as well, you can exchange them in various situations, or substitute one for another.
Reply
#8

Quote:
Originally Posted by trukker1998
Посмотреть сообщение
The function always has to return something, the standard is 1.. you could check it, and if is doesn't work you can return 0..
Many functions in samp api have "return value of this function is not defined" in wiki. Also there is warning 209, which will tell you that you tried to use return value of function which simply doesn't have one.
Reply
#9

So Number 1 and 3 do the same job.
Reply
#10

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Many functions in samp api have "return value of this function is not defined" in wiki. Also there is warning 209, which will tell you that you tried to use return value of function which simply doesn't have one.
Despite what the wiki says, most API functions actually do return 1 on success and 0 on failure, eliminating the need for an extra bothersome IsPlayerConnected check.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)