generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

quick question about returning in functions

Previous Thread :: Next Thread 
expoundings is online. expoundings
Joined: 02 Feb 2013
Total Posts: 2359
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 is not online. 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
expoundings is online. expoundings
Joined: 02 Feb 2013
Total Posts: 2359
24 Dec 2015 11:45 PM
how would i use an if statement to compare the returned value to something else?
Report Abuse
cbass25 is not online. 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 is not online. cbass25
Joined: 03 Jul 2009
Total Posts: 2957
24 Dec 2015 11:46 PM
if returnstuff() == otherThing then
Stuff
end
Report Abuse
expoundings is online. expoundings
Joined: 02 Feb 2013
Total Posts: 2359
24 Dec 2015 11:47 PM
thanks
Report Abuse
DrHaximus is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image