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

How do you iterate through function parameters?

Asked by 4 years ago

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.

0
Not sure but are you looking for [i]? What do you mean by parameters, I’m just not well versed in this. Benbebop 1049 — 4y
0
Parameters in functions is what I mean by parameters. awesomebanana2018 36 — 4y

1 answer

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

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")
0
Thanks! awesomebanana2018 36 — 4y
0
for i,v in pairs{...}do end; lol SoftlockedUnderZero 668 — 4y
0
nil cannot be concatenated programmerHere 371 — 4y
Ad

Answer this question