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

Is there any way to have a varying amount of arguments in a function?

Asked by 5 years ago
Edited 5 years ago

Hello, I'm trying to make some custom functions. One of these functions is the "Find" function; this function returns a table with other functions inside. This table is "representing" remote events/remote functions. It has a function under "Fire" which sends information to the server using a remote event. Basically if I had a remote event "Fire" would be like: Event:FireClient(player, [a varying amount of arguments]). So is there any way that I can make a function with a varying amount of arguments that processes them and sends them through a remote event/remote function?

Thanks

0
You can pass a table through a function. Event:FireClient(player, tableWithArguments) lolzmac 207 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Variadic functions


varaidic functions can be achieved, like other languages with an ellipsis (...)

An example would be:

local function foo(...)
    local args = {...}
    for i,v in pairs(args) do
        print(i,v)
    end
end
foo(1,2,3,4,56,7);

something like this can also be achieved if want one definite parameter and a varying range of other parameters

local function foo(name,...)
    local args = {...}
    for i,v in pairs(args) do
        print(i,v)
    end
end
foo("foot",1,2,3,4,56,7);

so for your case this would be

Remote.OnClientEvent:Connect(function(plr,...)
    --blah blah blah
end)
0
thanks so much I never knew about this thumbtack0 2 — 5y
Ad

Answer this question