Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Pass in Table as a function's Arguments?

Asked by 6 years ago
function printabc(a,b,c)
    print(a,b,c)
end

local list = {1,2,3}
printabc(list)

The above code prints "table:1234567 nil nil"

Is there anyway way, without saying "print(list[1], list[2], list[3])", that the above format will work?

1 answer

Log in to vote
0
Answered by 6 years ago

You can't print a table. You can unpack it though.

local function printabc(a, b, c)
    print(a, b, c)
end

local list = {1, 2, 3}

printabc(unpack(list)) -- will unpack the table and print its elements 
0
Oh thank god. Awesome! tentastic 32 — 6y
Ad

Answer this question