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: return

Previous Thread :: Next Thread 
SmoothPlastic is not online. SmoothPlastic
Joined: 16 Dec 2013
Total Posts: 697
14 Jun 2015 11:43 PM
Can someone explain return to me?
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
14 Jun 2015 11:45 PM
function hello()
return "Hello"
end

function hello2()
print("Hello")
end

ok.. so...

for return... it just is stutffffff

local hi = hello()

print(hi)

-> "Hello" because we made hello() return "Hello"

print(hello()) does the same thing
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
14 Jun 2015 11:46 PM
That was a horrible example.

function add(one, two)

return one _ two

end

print(add(5,5)) --> 10
print(add(6,6)) --> 12
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
14 Jun 2015 11:47 PM
That _ should be a +
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
14 Jun 2015 11:47 PM
urs was not any better
Report Abuse
SmoothPlastic is not online. SmoothPlastic
Joined: 16 Dec 2013
Total Posts: 697
14 Jun 2015 11:50 PM
function add(one, two)

return one + two



could you explain that a little more?

like what does the "one, two" mean in the "function add()"

and what would returning them do? e.o
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
14 Jun 2015 11:56 PM
one would be a parameter, two would be aswell.

you know how we do

function add(one, two)

one and two are basically variables for when you call it like

add(1,2)

then the return

function add(one, two)
return one + two
end

in return it adds the two numbers (hopefully numbers...) and then returns it.

so like

local three = add(2,1)

because 2 + 1 = 3, right?

then if we wanted to print 3 we could do it two ways now

print(three) or print(add(2,1))

so yeah
Report Abuse
SmoothPlastic is not online. SmoothPlastic
Joined: 16 Dec 2013
Total Posts: 697
14 Jun 2015 11:59 PM
what's the purpose of it if you could just print the numbers?

is return even necessary to use?
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
15 Jun 2015 12:01 AM
yes, yes it is.

look at this snippet i made for loading asset ids for a hat;

function GetMeshAndTextureIds(hatId)
for _,c in next, game:GetService("InsertService"):LoadAsset(hatId):GetChildren() do
if c:IsA("Hat") then
return {c.Handle.Mesh.MeshId, c.Handle.Mesh.TextureId}
end
end
end

it returns the meshid and textureid of a hat.

so, to get one of them you'd do local MeshId = GetMeshAndTextureIds(some_random_hat_id_here)[1] and yeah

so it is useful
Report Abuse
SmoothPlastic is not online. SmoothPlastic
Joined: 16 Dec 2013
Total Posts: 697
15 Jun 2015 12:05 AM
this whole "return" thing confuses me, idk why. It seems like it should be easy.. >.>
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
15 Jun 2015 12:07 AM
it's easy once you understand it. trust me. i remember getting confused with this return stuff, but do you understand parameters?

function test(a,b)
print(a..b)
end

you get that, right?
Report Abuse
SmoothPlastic is not online. SmoothPlastic
Joined: 16 Dec 2013
Total Posts: 697
15 Jun 2015 12:08 AM
if by parameters you mean...

a = "hello"
b = " how are you"


print(a.. b)
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
15 Jun 2015 12:10 AM
no nonono

like when you call a function

test("hello", " how are you")

would do the same thing
Report Abuse
SmoothPlastic is not online. SmoothPlastic
Joined: 16 Dec 2013
Total Posts: 697
15 Jun 2015 12:13 AM


so like


function test(num1, num2) -- they work as variables right now


return num1, num2 -- idek wot it was to do with anything haha

end

lol = test(2,2)
print(lol)


i think i get that much, it's just I am confused about the return's role in the script
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
15 Jun 2015 12:16 AM
check this out

http://wiki.roblox.com/index.php?title=Return#Using_Return

maybe it explains more than i do
Report Abuse
SmoothPlastic is not online. SmoothPlastic
Joined: 16 Dec 2013
Total Posts: 697
15 Jun 2015 12:19 AM
i sorta understand, but couldn't you just use regular prints and stuff for basic stuff like that?
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
15 Jun 2015 12:25 AM

The whole point of these examples is detailing how it works.

Later it could like like

function DestroyAllFrom(place)

local children = place:GetChildren()

for _, v in pairs(children)do
v:Destroy()
end

return #children --return number of children destroyed

end

local destroyed = DestroyAllFrom(game.Workspace)

print(destroyed)
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