[Help] Return function
Hey guys,
So, i'm trying to lear pawn scripting and i'm doing it via the documentation stated in this forum, with the help of the Allied Modders Wiki. I'm dividing this into sectors to better understand the parts that compose the whole. I'm stuck in here, as i don't fully understand what's the return function job. Code:
//This is a function that takes no parameters and returns 1. //When activated, it uses the (non-existant) print function. show() { print("Hello!") return 1 //End, return 1 }If it didn't have the return function, wouldn't it be the same result? Being, printing the word "Hello"! Sorry for my nooby question, but i like to make sure i fully understand each part to not make basic errors when i really start programming. Thanks for your help in advance. |
Re: [Help] Return function
It doesn't do much in this case; other than returning 1 if above code is executed correctly.
Since it returns 1 if the code is executed correctly, the function would allow you to check whether it succeeded or not: Code:
|
Re: [Help] Return function
for example,
if you dont write " return 'anything' " the function will continue, function will 'never' stop and this will generate errors. And to prevent these mistakes you use the return to "stop"/"end" the function. |
Re: [Help] Return function
As said above, you can return to block the code from continuing;
Code:
|
Re: [Help] Return function
Thank you, now i fully understand the return function. To resume, it is to halt the the function to that section of code.
And what about the number? Like in the case i posted, it ends with return '1'. What's the function of the number '1'? Thank you for your clarifying help. |
Re: [Help] Return function
It's simply a number. It can be any number. It can allow you to check whether the function was successfully executed or not for example, or perhaps check if it's the 'type' you wanted.
Code:
You could check what I did in an include file I made for a guy here on the forums. It returns certain values in case the weapon is invalid, or if client is invalid.. etc. Here's the link: http://forums.alliedmods.net/showpos...6&postcount=12 |
| All times are GMT -4. The time now is 08:25. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.