local Table = {
Name = "Apple";
Consumable = true;
}
print(Table["Name"])
print(Table.Consumable)
It will print Apple and true
I want to know, is there a difference between using Table["Key"] and Table.Key?
local Table = {
Name = "Apple";
Consumable = true;
}
print(Table["Name"])
print(Table.Consumable)
It will print Apple and true
I want to know, is there a difference between using Table["Key"] and Table.Key?
You can get names with gaps in them using [""] and if you don't want to put in that effort you can just use . with no gaps in the variable.
example:
local t = {["lol hi"] = true}
print(t["lol hi"])
then ofc
local t = {lol_hi = true}
print(t.lol_hi)
what wouldn't work is:
local t = {lol hi = true}
-- or
local t = {["lol hi"] = true}
print(t.lol hi)
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Actually [""] can be used to get names with any illegal characters
Ah right, thanks!