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

How do you use (...) with a function?

I rememeber I saw this a while back on the wiki, but I can't quite remember. It was using a hopperbin, something like:

function hopperbin(...)
	(...)
	-- code
end

local x = hopperbin(function())

end)

I understand this is a vague question, but I really can't find what I'm looking for anywhere. If anyone knows or has the wiki link I'm looking for (not the Variadic function page) that would be a big help. Thanks.

3 comments

0

this is the 30000th question asked!

0

Hurray :D Still really need an answer tho

1 answer

✓ Accepted answer

Variadic arguments
Is it okay if I bring friends?

The ... signifies that the function can take multiple arguments, which get stuck into a tuple represented by the varargs ... variable. There are several ways to use this:

  • To unpack them into variables
function vari(arg1, ...)
	local arg2, arg3, arg4 = ...
end
  • To iterate through them
function vari(...)
	local args = {...} -- Pack into a table
	for k,v in next, args do -- Iterate
		print(k,v)
	end
end
  • To pass them on to another function
function vari(...)
	print("Banana cupcakes:", ...)
	print(...)
end

"Where did I see it?"
The code probably looks a little like this:

local deb = false;
function debounce(f,...)
	if deb then return end;
	deb = true;
	local ret = {f(...)};
	deb = false;
	return unpack(ret)
end

Which debounces a function and returns everything from it. If you're interested, unpack also returns a tuple similar to ...

2 comments

0

Very helpful, have your 500th Reputation Point :D

0

Sweet.

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