View Single Post
03/18/20, 05:45 AM   #12
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,989
It should work the same as you do not create a "copy" but set a kind of "pointer" to the control/table.
Maybe create a table for your addon like
MyAddonName = {}
and then assign the uielement to this table so you can inspect the global table of your addon ingame to see what values it got.
MyAddonName.UiElement = AddonNameUiElement

-> If your local variable is created as the global variable exists properly already! Else the local variable will be nil
So make sure to create the XML controls before you access them. You can use your addon's txt file to load the XML before your lua code.
And in your lua code use the EVENT_ADD_ON_LOADED to be sure your addon is ready, to access other addons/your addons controls etc (though baiscally only needed to access other addons as your txt file should handle the creation of the XML stuff before your lua file already).

-> You can use addons like merTorchbug (check the comments of the addon for an updated version!) or zgoo to check ingame the contents of global variables (no local!)
-> So if you remove the local in front of UiElement and do a /tbug UiElement it should show you either nil in the chat or open an inspector which shows you what the variable got as information (if it's a table/object it should show you the functions, variables etc. and an __index which contains the "parent's" class functions and variables, and so on (->__index = lua metatables).


More info about tables: https://wiki.esoui.com/LUA_Tables

lua will just make a difference between tables and normal variables.

Table:
Lua Code:
  1. local table1 = {
  2.  [1] = "test"
  3. }
  4. local myTablePointer1 = table1[1] --will point to entry [1] in table1 -.> returning the value "test" or whatever it will be
  5. myTablePointer1 = "Hello" -- Will change the value of the table1[1] to "Hello"

Not sure about the following variable anymore 100% but I think it should be correct
Variable:
Lua Code:
  1. local var1 = "Hello"
  2. local var2 = var1 --Will make a "copy" of var1. var2 = "Hello"
  3. var2 = "World" --var1 = "Hello", var2 = "World"

And another "starters" lua question thread for some other questions you may run into:
https://www.esoui.com/forums/showthr...table+variable

Last edited by Baertram : 03/18/20 at 05:52 AM.
  Reply With Quote