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 two things

Previous Thread :: Next Thread 
FireController1847 is not online. FireController1847
Joined: 17 Jan 2013
Total Posts: 1828
22 May 2016 10:18 PM
Is it possible to return two things in a function... and, honestly, how do I use returns? I've never really figured it out. Would it be something like...

function Test()
return "Hello", "Hello2"
end

Test()
print(Test[1])

... or something like this?


Report Abuse
FireController1847 is not online. FireController1847
Joined: 17 Jan 2013
Total Posts: 1828
22 May 2016 10:23 PM
Nevermind, I found out that this works...

function test(String1)
return {String1, "String2"}
end

x = test("String1")
print(x[1])
print(x[2])


#code function brag() print("R$1,712") end
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
22 May 2016 10:25 PM
This also works.

function Test()
return "String1", "String2"
end

local A, B = Test()
print(A)
print(B)


Report Abuse
FireController1847 is not online. FireController1847
Joined: 17 Jan 2013
Total Posts: 1828
22 May 2016 10:25 PM
Hmm, I think I might do it my way, but that is a good way to keep in mind.


#code function brag() print("R$1,712") end
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
22 May 2016 10:27 PM
It kind of depends on the need. They can also be interchanged very easily.

If you use the function I declared above, you can turn it into a table:
local AB = {Test()}
print(AB[1])
print(AB[2])

Using your function, you can turn it into a tuple:
local A, B = unpack(Test())
print(A)
print(B)


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