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

havent seen this being used often,what does this parameter mean?

Asked by 5 years ago

quick newbie question, i havent seen this being used often. can anyone explain what the (...) refers to?

function Graph:newNode(...)

1 answer

Log in to vote
1
Answered by 5 years ago

So, the three dots are an ellipsis. In functions, they are used as a substitute to having named parameters. For example:

local function foo (...)
    print(#{...})--8
    for _,v in pairs({...}) do
        print(v)
    end
end

foo("thy","they","2",121,343,4323,"fbi","boo")

the ellipsis is particularly useful when you are sending a lot of arguments to a function, and instead of having to create a parameter for every single argument you have. For Example:

game.ReplicatedStorage.Remote.OnServerEvent:Connect(function(...)
    local a = {...} --table of arguments
    print(a[1],a[3],a[2],a[6],a[9])
end)
Ad

Answer this question