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.

2 Likes

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"

--]]
2 Likes

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.

2 Likes