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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 29 Jun 2011 |
| Total Posts: 80 |
|
|
| 19 Jul 2017 12:00 AM |
| i feel stupid, thanks for the help |
|
|
| Report Abuse |
|
|
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 |
|
|