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

Why do you put ("..."), in a functions parameter sometimes? [not answered]

I've seen this very often;

function co(...)
	-- do stuff
end

I'm focusing on the parameter, like why do you use it?

7 comments

0

It says nothing about using (...), in a parameter.

0

And ROBLOX LUA, and LUA are two different languages.

0

It's the same base language, so most stuff that you can do in Lua will work in Roblox. Roblox's Lua is just adapted to the platform and the game world.

0

I presume the ellipses is just a wildcard? If you could give a script example I might be able to answer this.

1 answer

✓ Accepted answer

It allows you to take any amount of variables as a tuple.

function VariadicFunction(...)
	local Arguments = {...} --contain tuple thing
	local n = 0;
	for i, v in pairs(Arguments) do
		if not tonumber(v) then error("argument "..i..": not a number") end
		n = n + v;
	end
	return n
end

VariadicFunction(4,5,6,7,8,9,10) --gives you 4+5+6+7+8+9+10, too lazy to calculate heehee hoohoo

1 comment

0

Wow! Thanks

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