![]() |
Index Nill and Square Brackets
I have two questions if anyone can help me out. Thanks!
First Question: Can anyone tell me why one of these works and the other does not? TargetHPBar[1] turns out nil for ZO_TargetUnitFramereticleover, but it works for ZO_PlayerAttributeHealth Lua Code:
I'm trying to do this: Lua Code:
Second Question: Looking at other addons I can't figure out what the difference is between some of the assignments I see like: Lua Code:
Thanks ;) |
"blabla" and 'blabla' is exactly the same thing. "..." and '...' are used to delimit a string. In PHP they are slightly different ("..." lets you insert variables on the fly like : "my max health is $MaxHP"), not sure about Lua but afaik they are stricly the same.
The difference between DAMAGE_COLOR and [DAMAGE_COLOR] is that [] are used to define a table index so it's likely that [DAMAGE_COLOR] = stuff is part of a table, where DAMAGE_COLOR = stuff is just a variable defined with name DAMAGE_COLOR Example without table : Code:
DAMAGE_COLOR = "red" Lua Code:
Or Lua Code:
Which is the same thing. Then you can access your colors with either i.e. Colors.DAMAGE_COLOR or Colors["DAMAGE_COLOR"]. Now for [DAMAGE_TYPE_NONE] without quotes this is different because the thing will return you the value with index of the DAMAGE_TYPE_NONE value. Example : Lua Code:
To sum up : ".." or '..' is for string. [] is for table indexes. ["MyIndex"] is for value with index "MyIndex" and [MyIndex] is for value with index *content of MyIndex* - if that makes sense :D because with [MyIndex] the MyIndex is not considered an index but a variable. Another silly example : Lua Code:
About your first question : I think TargetHPBar[1] turns out nil because ZO_TargetUnitFramereticleover IS nil. Did you check for a typo ? :D Lua is case-sensitive. |
All times are GMT -6. The time now is 01:30 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI