Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

1 comment

0

You can pass a table through a function. Event:FireClient(player, tableWithArguments)

1 answer

✓ Accepted answer

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)

1 comment

0

thanks so much I never knew about this

This discussion is preserved as it was. New answers, comments, and votes are closed.