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 iterate through function parameters?

I can't figure out how to iterate through parameters. Usually I would use the

for i,blank in pairs(table) do
	print("One of the elements of this table is: ".. blank)
end

But I don't know how to put the parameters in instead. I'm also open to other functions or any others ways to do it.

2 comments

0

Not sure but are you looking for [i]? What do you mean by parameters, I’m just not well versed in this.

0

Parameters in functions is what I mean by parameters.

1 answer

✓ Accepted answer

There's multiple ways you could go about this, but the easiest solution is to use ... as your parameter instead. This will let you iterate through a table in the scope of the function.

An example

function printAll(...) 
	local arg = {...}

	for i, blank in pairs(arg) do
		print("One of the elements of this table is: ".. blank)
	end
end

printAll(5, 9, 8)
printAll("hello", nil, "world")

3 comments

0

Thanks!

0

for i,v in pairs{...}do end; lol

0

nil cannot be concatenated

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