|
| 01 Apr 2017 10:55 PM |
Goal: Put entries of a table into the input of a function. The number of entries is known only to the script.
Table=part:GetChildren()
function stuff(Table[1],Table[2],Table[3]...) end
Basically I want it to continue adding inputs for each member of the table. Is that even possible? |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2017 10:57 PM |
local tab = part:GetChildren()
local function func(...) print(...) end
func(unpack(tab))
|
|
|
| Report Abuse |
|
|
|
| 01 Apr 2017 10:59 PM |
print is an example of a variadic function (vararg)
local function count( ... ) print( #( {...} ) ) --... will be a sequence of inputs, not a table (1,2,3 vs {1,2,3}) end
count( 2, 5, "HI", string )
you can place other arguments in a vararg function, but only beforehand
local function countMult( multiplier, ... ) print( #( {...} ) * multiplier ) end
countMult( 2, 5, "HI", string ) |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2017 11:00 PM |
That's completely irrelevant...
|
|
|
| Report Abuse |
|
|
|
| 01 Apr 2017 11:02 PM |
| ik, but also why do you need to do that? just give them the table if you need to send the arguments.. unless you are storing arguments it needs to use in a table |
|
|
| Report Abuse |
|
|
|
| 01 Apr 2017 11:06 PM |
I understand what you mean, but OP probably has a reason why he wants them each as a parameter. If he's doing something where the variable number of arguments would end up in a table anyway then yeah, of course you would just send the table.
|
|
|
| Report Abuse |
|
|