|
| 24 Dec 2015 11:42 PM |
i don't use return much and i'm wondering if i'm doing this right
function returnstuff() local var = 1 + 2 return var end
returnstuff() print(var) |
|
|
| Report Abuse |
|
|
DrHaximus
|
  |
| Joined: 22 Nov 2011 |
| Total Posts: 8410 |
|
|
| 24 Dec 2015 11:43 PM |
the return value is passed to whatever calls it, ie
result = returnstuff() print(result)
==> 3 |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2015 11:45 PM |
| how would i use an if statement to compare the returned value to something else? |
|
|
| Report Abuse |
|
|
cbass25
|
  |
| Joined: 03 Jul 2009 |
| Total Posts: 2957 |
|
|
| 24 Dec 2015 11:45 PM |
| You could also say print(returnstuff()) as well, if I'm not mistaken. |
|
|
| Report Abuse |
|
|
cbass25
|
  |
| Joined: 03 Jul 2009 |
| Total Posts: 2957 |
|
|
| 24 Dec 2015 11:46 PM |
if returnstuff() == otherThing then Stuff end |
|
|
| Report Abuse |
|
|
| |
|
DrHaximus
|
  |
| Joined: 22 Nov 2011 |
| Total Posts: 8410 |
|
|
| 24 Dec 2015 11:48 PM |
@cbass well yeah, but it's more accurate to say that to use a returned value is that it must be captured, ie:
function test() return 4 end
test() => the return value is not captured, nothing is done with it
print( test() ) => return value is passed as an argument to print as an rvalue instead of an lvalue |
|
|
| Report Abuse |
|
|