Here is an example line of code:
local table = {"Value1","Value2","Value3"}
The problem is, "table" is already a feature {table.insert(table,value)} Is there any disadvantage to using this type of variable, and if so, then what?
This is allowed as far as the Lua language and Roblox scripting is concerned. The drawback is that it's confusing.
So it's generally a bad idea to "hide" or "replace" a common name, because it's a violation of the Principle of Least Astonishment. (And software design principles apply even in a project you never intend to share with anyone else, because if you don't fully understand the technical details of an unusual pattern, and/or you set the project aside for a while and later return to it, it can easily be you that gets hit by the gotchas.)
A side note about this type of "hiding" local declaration: A Lua local
declaration applies to a specific scope, up to the end of the smallest "block" that contains the declaration. (A block is a portion of code that starts with if
, for
, while
, repeat
, do
, or function
, and ends with the matching end
.) After the end of that block, the local declaration no longer has any effect, and the name's previous meaning is visible again.