Here is the thing.
When you refer to table[index], you are not referring to table.index, but you are instead referring to table[0].
Point here being:
and now Table[index] refers to table[5]
If you however use Table["index"] then you are referring to table.index
By otherwords, without quotes around the name, you are not referring to the name, but to the value of a variable.
With Quotes, you are referring to the name.
[index] = what ever value variable index holds
["index"] = refers to tableitem index - table.index
Another thing to notice is in using quotas that there is difference in referring to them.
Code: Select all
tb = {}
tb["gr"] = 1
tb["Gr"] = 2
tb["GR"] = 3
Debugprint(tb["gr"])
Debugprint(tb["Gr"])
Debugprint(tb["GR"])
Debugprint(tb.GR)
End Result, you can notice that gr, Gr, GR are all different table items, each holding a different value, and only referenced when actually using the exact right capital-noncapital combination of letters.
However, when using tb.gr, tb.Gr, or tb.GR, they all reference to the same, tb["gr"] version.
Therefore I would suggest to use tb.gr both when creating them, as well as when referencing to them in the code, so that you dont have to worry about capital-noncapital letters.
As you could for example:
and it would work.
You could also do in such way that when you create the variable use tb.GR method, but when referencing it, use
LowerStr() command.
As example:
Code: Select all
tb = {Gr = 1}
Debugprint( tb[ LowerStr("GR") ] )
And you would now be referencing tb.gr
Adding
LowerStr() makes things less readable, but there are situations where it is useable, for example, you might want for claritys sake use Capital letters sometimes when choosing a Color, but then later need them to access a table, or you might even want them uppercase in some case:
Code: Select all
Color = TextColor
Switch UpperCase(Color)
case GR
case BL
EndSwitch
Code: Select all
ColorToUse = "GR"
ColorToUse = LowerStr(ColorToUse)
TextOut(10, 10, "test", {color=_Cols[ColorToUse]})