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: can someone explain "Return" to me?

Previous Thread :: Next Thread 
Frosteus is not online. Frosteus
Joined: 21 Dec 2013
Total Posts: 13470
14 Aug 2017 09:39 AM
wiki and tutorials confuse me more and more
Report Abuse
SlimeMan22 is online. SlimeMan22
Joined: 10 Mar 2012
Total Posts: 1210
14 Aug 2017 09:42 AM
function ReturnOne()
return 1
end

print(ReturnOne())






Šçrätčh ïïś üśëd bÿ łëvëł 17 äñöñ DÖŠ HTMŁ hæx0rs whö üsë ŚQŁ++ ïïńśpëçt ëłæmęñtïïñg
Report Abuse
Frosteus is not online. Frosteus
Joined: 21 Dec 2013
Total Posts: 13470
14 Aug 2017 09:47 AM
wut?...
Report Abuse
iiNemo is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
14 Aug 2017 09:48 AM
function add(num1, num2)
print("Finding sum.")
return num1 + num2
--print("Sum found")
end
 
x = add(5, 2)
print(x)

Output:
7
Report Abuse
Frosteus is not online. Frosteus
Joined: 21 Dec 2013
Total Posts: 13470
14 Aug 2017 09:51 AM
shoving code tht i alredy read on the wiki doesnt help x.x
Report Abuse
iiNemo is online. iiNemo
Joined: 22 Jul 2013
Total Posts: 2380
14 Aug 2017 09:54 AM
function Add(Num1, Num2)
return Num1 + Num2
end

Add(5, 1) -- Num1 will equal 5 num 2 will equal 1

return will transform Add(5, 1) to be 5 + 1 which is six so like

if Add(5, 1) == 6 then
print('NemoIsAwesome')
end
Report Abuse
sonihi is not online. sonihi
Joined: 27 Jun 2009
Total Posts: 3655
14 Aug 2017 10:00 AM
So you may have a function that calculates something very complicated and you don't wan't to paste the code that calculates it everytime like math.log(a*b^2).

So you make a function:

function ComplexCalculation(a,b)
return math.log(a*b^2)
end

And now you try to calculate this complicated thing for numbers 4 and 3

ReturnedValue=ComplexCalculation(4,3)

Now the function "returns" or gives you the value and writes it in the Returnedvalue variable.
Report Abuse
1pie23 is not online. 1pie23
Joined: 11 Jul 2010
Total Posts: 1865
14 Aug 2017 10:08 AM
return also stops remaining code from running:

local val = false

if val == false then
return
end

print("Do you see this in output?")


Hint: you don't see it in the output.
Report Abuse
Frosteus is not online. Frosteus
Joined: 21 Dec 2013
Total Posts: 13470
14 Aug 2017 10:13 AM
so confused x.x
Report Abuse
sonihi is not online. sonihi
Joined: 27 Jun 2009
Total Posts: 3655
14 Aug 2017 10:17 AM
Just try to use return in a couple examples.

Try this:

function add(Number1,Number2)
local sum=Number1+Number2
return sum
end

a=add(3,5)
print(a)

and another thing

function add(Number1,Number2)
local sum=Number1+Number2
end

a=add(3,5)
print(a)
Report Abuse
gohan31865 is not online. gohan31865
Joined: 30 Jan 2011
Total Posts: 895
14 Aug 2017 10:17 AM
it takes values and then gives them back to u. i find it to be just a glorified print function
Report Abuse
Frosteus is not online. Frosteus
Joined: 21 Dec 2013
Total Posts: 13470
14 Aug 2017 10:19 AM
wuts the difference between

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

a = addNumbers(3, 5)
print(a)

with the return and without?

cuz the numbers get plugged in either way, no?
Report Abuse
Frosteus is not online. Frosteus
Joined: 21 Dec 2013
Total Posts: 13470
14 Aug 2017 10:21 AM
waitwaitwait so return takes the sum and switches it with the numbers u took to make the sum!??!?!
Report Abuse
RobuxLife is not online. RobuxLife
Joined: 19 Sep 2012
Total Posts: 13336
14 Aug 2017 11:05 AM
alright think of this

you made a function, right?

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

now, you can make a variable BE that function so like

local x = OOF(5, 5)

basically, you're doing 5 + 5, and putting it into a variable. By doing this;

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

you are printing it not returning it. so OOF(5, 5) would print out 10. by doing the return one, you can put it into a variable, and then print that variable whenever you like, or do whatever you want with it


- RobuxLife | Discord - RobuxLife#4128 |
Report Abuse
Saldor010 is online. Saldor010
Joined: 20 Sep 2010
Total Posts: 1035
14 Aug 2017 11:13 AM
Return is one of the only ways a function can send output back to the caller.

For example, if you were a parent, and you told your kid to go clean his room, he may or may not do it. The only way you would know for sure that he did it, is to see for yourself by checking the room. So in Lua, we would write it something like this:
--
function cleanRoom()
local didTimmyWantToCleanHisRoom = false
local roomIsClean = false
if roomIsClean == true then
return true
else
return false
end
end

roomIsClean = cleanRoom()
print("Did timmy clean his room? "..roomIsClean)
--
roomIsClean is the only variable you will ever see in this example, because it's the only variable ever returned. You can't see whether timmy wanted to clean his room or not, all you see is whether the room was actually cleaned.

I hope that made sense to you.
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