How to use "..." in functions

So i’ve found this on the internet,

in a function you can use a “…” to get infinite amount of Params.

How does this work?

Also, is this possible, checking of A = false or A = true in the “…”

Example

local function MoveItem(Player, Part, ...)
	
	-- what to do with the "..."?
	
end

thats a variadic function a function that will accept any number of arguments u can look it up
Example:

local function variadic(named, ...)
    local arguments = {...} -- pack the extra arguments into a table
    print("Named argument = ", named)
    for i, value in ipairs(arguments) do
        print("Input No. ", i, "=", value)
    end
end
 
variadic(10, "Hi", 20, "Variadic Function")
1 Like

Do local variable = {…}
That will unpack the paramaters and put them all into the table

1 Like

This is comparable to *args and **kwargs in python.

Also to answer your question:

Yes it is, here’s how you do it:

local function MoveItem(Player, Part, ...)
    local extraArgs = {…}
    if extraArgs["A"] == true then
        print("A is true")
    elseif extraArgs["A"] == false then
        print("A is false")
    end
end
3 Likes

Thanks everyone, infortunatly i can only mark 1 as a solution so…

1 Like