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
 

Re: I don't understand return!

Previous Thread :: Next Thread 
bigboy77584 is not online. bigboy77584
Joined: 06 Jan 2009
Total Posts: 1003
01 Jun 2015 09:08 PM
I know lua (not Roblox lua though) alright. I can make many differnt programs but I have yet to understand return.
i.e.

--------------------------------------
--what is the difference between:

function add(num1, num2)
print(num1 + num2)
end

--and

function add(num1, num2)
return num1 + num2
end
------------------------------------
Mainly when returning strings and numbers in functions, I do not understand what the advantage of it over print is. Help is much appreciated!! Thanks in advance.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Jun 2015 09:08 PM
the first one will print the sum
the second one will return the sum to the caller

Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
01 Jun 2015 09:09 PM
return returns a value

function echo(x)
return x
end

b = echo("POTATO")

print(b)

that would print potato
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
01 Jun 2015 09:09 PM
print is just a function that displays something in the output. Return returns back the value to the caller:

function add(num1, num2)
return num1 + num2
end

local var = add(5, 5) --this variable is now 10



Whereas this:


function add(num1, num2)
print(num1 + num2)
end

local var = add(5,5) --this variable is nil
Report Abuse
CrowClaws is not online. CrowClaws
Joined: 04 Jul 2010
Total Posts: 4466
01 Jun 2015 09:10 PM
@bigboy return works the same in almost all languages


It has advantages bc u dont' always pring stuffs.
Say u wanted to make a function that'd return a value u want to use e.i


function add(num1, num2)
return num1 + num2
end

print(add(1,2)*3)

or something
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
01 Jun 2015 09:10 PM
What if you don't want to print it?

function add(num1,num2)
return num1 + num2
end

Workspace.Baseplate.Position = add(56, 387)
Instance.new("Explosion", Workspace).BlastRadius = add(18, 58)
Report Abuse
secret6timb1 is not online. secret6timb1
Joined: 11 Sep 2013
Total Posts: 1817
01 Jun 2015 09:11 PM
@kingkiller1000


Return doesn't print, it returns

dictionary.com
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
01 Jun 2015 09:12 PM
Idiot above.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
01 Jun 2015 09:12 PM
When the hell did I say that?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Jun 2015 09:15 PM
v3 I say, v3!
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
01 Jun 2015 09:16 PM
Yeah, I just noticed that. Editing mistake.
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