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 
Excenal is not online. Excenal
Joined: 29 Jun 2011
Total Posts: 80
18 Jul 2017 11:54 PM
how would i return multiple values and use them
for ex -

local function = poop()
a = 1
b = 2
c = 3
return a,b,c
end

poopnums = poop()
print(poop[1]) - prints 1
print(poop[2]) - doesn't work and so on
Report Abuse
Excenal is not online. Excenal
Joined: 29 Jun 2011
Total Posts: 80
18 Jul 2017 11:56 PM
################ # mean't print(poopnums[1]) and etc, just typing real fast
Report Abuse
PhantomVisual is not online. PhantomVisual
Joined: 08 Apr 2011
Total Posts: 2025
18 Jul 2017 11:58 PM
local function = poop()
a = 1
b = 2
c = 3
return {a,b,c}
end

poopnums = poop()
print(poopnums[1])
print(poopnums[2])

Now it works or:

local function = poop()
a = 1
b = 2
c = 3
return a,b,c
end

poopnumsA, poopnumsB, poopnumsC = poop()
print(poopnumsA)
print(poopnumsB)


Report Abuse
VilgO is not online. VilgO
Joined: 15 Feb 2011
Total Posts: 518
18 Jul 2017 11:59 PM
In Lua functions return multiple values separately, not a single object that contains all the returned values.

local function foo() return 1, 2, 3 end

local a, b, c = 1, 2, 3
print(a, b, c) --> 1, 2, 3

local x = {foo()}
print(x[1], x[2], x[3]) --> 1, 2, 3
Report Abuse
Excenal is not online. Excenal
Joined: 29 Jun 2011
Total Posts: 80
19 Jul 2017 12:00 AM
i feel stupid, thanks for the help
Report Abuse
VilgO is not online. VilgO
Joined: 15 Feb 2011
Total Posts: 518
19 Jul 2017 12:00 AM
It was supposed to be "local a, b, c = foo()". :\
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