Cannot set a variable to an index of "..." (Variadic Functions)

I don’t know if this is a bug or not, but I can’t post in bug reports so I’ll assume I’m doing something wrong.
In a function with a variadic parameter, I can do

local args = {...}
args = args[1]

But not

local args = {...}[1]

Is there a reason for this?

Interesting. I guess the compiler doesn’t know how to deal with it.

Can you do:

local args = ({...})[1]

I bet you can.

2 Likes

Yeah… This works. I’m still so confused on why Roblox thinks there’s an issue, but your solution works so it really doesn’t matter.
I’d submit this as a bug report, but I’m not a regular.

Probably for the same reason that you can’t make an assignment and a statement at the same time. Technically that’s what this is doing.

For example, you can’t do:

local table_1 = {1, 2, 3}[1]

because this is both an assignment and a statement. I believe the parentheses break it into two parts at the compiler level

I’m not sure why, but for some reason I thought that was possible. That’s sorta why I made this topic in the first place
Thanks for your help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.