SA-MP Forums Archive
What's the difference between these ? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: What's the difference between these ? (/showthread.php?tid=496242)



What's the difference between these ? - AnonScripter - 21.02.2014

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;
}



Re: What's the difference between these ? - FilesMAker - 21.02.2014

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


Re: What's the difference between these ? - itsCody - 21.02.2014

Basically does the same I guess
Except the middle one?


Re: What's the difference between these ? - Misiur - 21.02.2014

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.


Re: What's the difference between these ? - trukker1998 - 21.02.2014

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


Re: What's the difference between these ? - FilesMAker - 21.02.2014

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 !


Re: What's the difference between these ? - Aerotactics - 21.02.2014

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.


Re: What's the difference between these ? - Misiur - 21.02.2014

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.


Re: What's the difference between these ? - AnonScripter - 21.02.2014

So Number 1 and 3 do the same job.


Re: What's the difference between these ? - Vince - 21.02.2014

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.