Thread Tools Display Modes
03/16/20, 09:51 PM   #1
fallenstd
Join Date: Mar 2020
Posts: 6
Lua XML targeting

Hi and sorry if this is a dummy question (spoiled C# dev here).
I am following tutorials found on wiki, thanks to the authors for that btw!, to learn the basics before trying my hand at a simple addon.

My first question is in regards of targeting the XML child controls. From other languages I am used to finding them by
Code:
Parent.Child.Grandchild.property
type of syntax. And even xml itself supports
Code:
$(parent)child
So Question is if there is a way not to have to every time do the whole strings? And if not, do you guys have some recommendations or plugin that has some kind of management of all the UI handles?

Second question is, what IDE do you guys use generally? I decided to go with VSCode as I do use it for work so relatively familiar with it.

Third question, what is a good way to explore all the great libs that people created and already have tons of stuff built? My tolerance for reinventing the wheel is getting low :-)

Cheers.

Last edited by fallenstd : 03/16/20 at 09:55 PM.
  Reply With Quote
03/17/20, 04:42 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
Welcome to ESOUI!

There are a few different ways how you can access controls. First you have to understand that every named control is automatically assigned to a global variable. For example when the have a structure with names like "MyAddonWindow" -> "$(parent)Container" -> "$(parent)Control" you will end up with three globals "MyAddonWindow", "MyAddonWindowContainer" and "MyAddonWindowContainerControl". That's also a common pitfall for new authors who name their addon's "namespace" table the same as their top-level xml control, not knowing that the control will be assigned to the global variable.

Each control also has an "OnInitialized" callback which passes the object to a Lua function. You can use the function GetControl(parent, "ChildName") to access elements under it, or directly call parent:GetNamedChild("ChildName") which is used underneath. Instead of passing an object you can also just pass the name to GetControl and it will fetch the global variable for you.

From XML you are a bit more limited, but you can use the same expansions used for naming the controls to access them relative to each other. In addition to "$(parent)" there is also "$(grandparent)" and in theory you should be able to create a custom constant with the <string> control and use that too.

For your second questions I suggest you check out this thread. Don't think anyone has made a working autocompletion for VSCode yet, but there are a few projects for other IDEs which could probably be repurposed.

As for libraries, there are not that many. It's probably easiest to sort the category by monthly downloads and read a few of their descriptions every day until you know them all by heart :P
  Reply With Quote
03/17/20, 12:05 PM   #3
fallenstd
Join Date: Mar 2020
Posts: 6
Great, that was a nice summary, thanks @sirinsidiator
in theory you should be able to create a custom constant with the <string> control and use that too
Not sure I quite got this one, was it for XML-XML targeting or targeting XML from LUA?

Most of it I kind of stumbled on, but having it written like this will definitely come handy.

I might also try and update some of the tutorials on wiki with this info if you don't mind?

I found there is a good plugin for VSCode that then does nice intellisense for the LUA syntax but cant link the libraries etc yet, so method and property discovery goes old school LookAtTheSourceCode approach.

Cheers!

Last edited by fallenstd : 03/17/20 at 12:52 PM.
  Reply With Quote
03/17/20, 12:10 PM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Already updated the XML UI on the Wiki with the information, thanks sirinsidiator.
https://wiki.esoui.com/UI_XML

https://wiki.esoui.com/UI_XML#Accessing_XML_controls

Maybe link to this in the tutorials.
  Reply With Quote
03/17/20, 12:30 PM   #5
Kyoma
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 125
The only lib you'll ever need
  Reply With Quote
03/17/20, 12:53 PM   #6
Scootworks
 
Scootworks's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2014
Posts: 312
Originally Posted by Kyoma View Post
https://giphy.com/gifs/the-office-no...12XMGIWtrHBl5e
  Reply With Quote
03/17/20, 12:57 PM   #7
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
For navigating the libraries, you can view the category Libraries or tell us specific functionality you may be looking for.

If you're doing a combat/location/data sharing based addon, you'd definitely want to look into existing libraries.

For creating a settings menu, LibAddonMenu. For custom right click menus, LibCustomMenu. For outputting to chat, LibChatMessage.
  Reply With Quote
03/17/20, 02:12 PM   #8
fallenstd
Join Date: Mar 2020
Posts: 6
Originally Posted by Rhyono View Post
For navigating the libraries, you can view the category Libraries or tell us specific functionality you may be looking for.

If you're doing a combat/location/data sharing based addon, you'd definitely want to look into existing libraries.

For creating a settings menu, LibAddonMenu. For custom right click menus, LibCustomMenu. For outputting to chat, LibChatMessage.
Nice, thanks a ton, this is a great summary of stuff I will need.

I am actually going to finish the tutorials first, and the onto my project.
Already discovered that declaring the control as local from string that I would otherwise use to call it does not seem to work. unless I am missing something
Code:
local UiW= NewAddonWindow
UiW.SetValue(x) -- doesnt work
NewAddonWindow.SetValue(x) -- does work
Or I am missing something.
  Reply With Quote
03/17/20, 02:19 PM   #9
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
Controls should be global and unique (because they are global). I (as an author of random addon X) expect to be able to see the controls of your addon.
  Reply With Quote
03/17/20, 03:13 PM   #10
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
Lua has a short hand way for defining member functions. When they are defined with function myTable:myFunction(a, b) it means the same as writing function myTable.myFunction(self, a, b).
When you call a method the same applies. For control instances you can assume all methods use this shorthand way, so what you are actually doing right now is passing the value to self instead of the expected argument. You need to either call UiW.SetValue(UiW, x) or for short UiW:SetValue(x).
  Reply With Quote
03/17/20, 03:54 PM   #11
fallenstd
Join Date: Mar 2020
Posts: 6
Originally Posted by sirinsidiator View Post
For control instances you can assume all methods use this shorthand way, so what you are actually doing right now is passing the value to self instead of the expected argument. You need to either call UiW.SetValue(UiW, x) or for short UiW:SetValue(x).
Aaah, great, this is what I was missing. Thanks a bunch!
I was aware of the two way of calling methods, just didn't think to try the : way for controls.
Cheers

ps. but this works only for members that come from LUA, not global vars that store the UI element names right?
I modified my code and it works for members under the LUA addon namespace, but not when I assign it to local
local UiElement = AddonNameUiElement
then calling UiElement:SetValue(x) does not do anything while calling element directly by id works AddonNameUiElement:SetValue(x)

Last edited by fallenstd : 03/17/20 at 05:21 PM.
  Reply With Quote
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,912
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
03/18/20, 01:22 PM   #13
fallenstd
Join Date: Mar 2020
Posts: 6
Originally Posted by Baertram View Post
...
Thank you @Baertram for this, very comprehensive, and I think this hit the spot, will test today.
Looks like the order of loading might be an issue, as my .lua was loading before .xml
  Reply With Quote
03/18/20, 01:27 PM   #14
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
Loading is sequential per the .txt declaration.
  Reply With Quote
03/18/20, 07:13 PM   #15
fallenstd
Join Date: Mar 2020
Posts: 6
Originally Posted by Rhyono View Post
Loading is sequential per the .txt declaration.
Yes, that part was very clear from tutorials, but what I didn't know is the exactly when certain handlers get registered. As the xml goes before lua, but in the xml there are event handler registrations for OnMoveStopped etc, so it was a bit unclear that if xml goes after lua then one cant do the local assignment of UI elements from Global vars.
  Reply With Quote
03/18/20, 07:22 PM   #16
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
The handlers in the XML are atatched to the controls you create in the XML so they will be fired after the controls were created.

Normally this should also happen if the xml is loaded before the lua file was loaded.
As long as the events of the xml control is not refrencing any lua code which is in a file that get's loaded after the xml, everything should be fine.
Like OnInitialized will fire as the control get's created -> lua code therefore must exist before xml creation.
But e.g. OnMouseDown could be even in another lua file loaded after the xml as the mouse click will most likely not happen automatically as the control get's created

OnMoveStopped also should only be fired if the control get's moved (manually or via lua code maybe). Never tested this if it fires as you somehow use the lua functions to move (reanchor) the control.
e.g. if in your lua file the event_add_on_loaded will load the SavedVariables and then reset the xml control to a saved position. Not sure if this will also trigger the OnMoveStop event then.

Last edited by Baertram : 03/18/20 at 07:25 PM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Lua XML targeting

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off