Local variable and Table variable with the same name?

Hello, just wondering if something like this

local SomeTable = {
   SomeVariable = {}
}

local SomeVariable = etc..

SomeTable.SomeVariable = "SomeString"

would cause a problem?

Edit: I was thinking there might be a time where the script mistakes SomeVariable inside the SomeTable as the local variable.

1 Like

From my understanding, it’d only cause a problem if you index it like this:

SomeTable[SomeVariable] = "SomeString"

Because this would then add a key/value pair into the dictionary using the variable rather than updating the pre-existing key called “SomeVariable”.


Example:

local SomeTable = {
	SomeVariable = {}
}

local SomeVariable = "hi"

SomeTable.SomeVariable = "SomeString"
SomeTable[SomeVariable] = "Another Value"

warn(SomeTable) -- [[ This prints the following:

["SomeVariable"] = "SomeString",
["hi"] = "Another Value"

--]]
1 Like

No they are different references however, if you were to do something like SomeTable[SomeVariable] this would error depending on what SomeVariable is set to.

1 Like