04/29/20, 09:19 AM | #1 | |
Join Date: Apr 2020
Posts: 9
|
Help with XML controls
Hi! I am new to Addon development, and I have been fiddling around trying things to get a hold on things.
However, I am stuck on something I don't quite understand yet... I have followed this tutorial: and from there I have added a auto ready check accept when using LFG Lua Code:
And it works perfectly! I just wanted to add now a message display that tells me when I'm close to full on my bag (less than 10 space left). I copied everything I did for the combat system in the tutorial (which still works well) and created a new XML file for this. However, whenever the addon should update with the message, I get the infamous "nil index...". Could someone give me a hand? .lua file: Lua Code:
.xml file: Code:
<GuiXml> <Controls> <TopLevelControl name="FightIndicator" mouseEnabled="true" movable="true" clampedToScreen="true"> <Dimensions x="200" y="25" /> <Anchor point="BOTTOM" relativeTo="GuiRoot" relativePoint="CENTER" offsetY="-20" /> <OnInitialized> -- LUA code here. This is where you'd check to see if the control needs to be hidden or not. FightIndicator:SetHidden(not IsUnitInCombat('player')) </OnInitialized> <OnMoveStop> RemiCustomAddon.OnIndicatorMoveStopFight() </OnMoveStop> <Controls> <Label name="$(parent)Label" width="200" height="25" font="ZoFontWinH1" inheritAlpha="true" color="FF0000" wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER" text="Fighting!"> <Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" /> </Label> </Controls> </TopLevelControl> </Controls> </GuiXml> Code:
## Title: RemiCustomAddon ## APIVersion: 100030 ## SavedVariables: RemiCustomAddonSavedVariables RemiCustomAddon.lua RemiCustomAddon.xml Fight.xml Thanks in advance! |
|
04/29/20, 10:57 AM | #2 |
RemiCustomAddonIndicator Where is this control defined?
It should be inside your XML file but I cannot see it. Is it in the other xml file? You need to post this then. Last edited by Baertram : 04/29/20 at 11:03 AM. |
|
04/29/20, 11:04 AM | #3 |
|
I'm wondering if that should be where it says FightIndicator currently.
|
04/29/20, 11:04 AM | #4 |
I guess it's in the 2nd xml file which he did not show us here:
RemiCustomAddon.xml |
|
04/30/20, 12:16 AM | #5 | |
Join Date: Apr 2020
Posts: 9
|
Missing XML file
I totally messed up sorry! Of course, here is the correct .xml file:
Code:
<GuiXml> <Controls> <TopLevelControl name="RemiCustomAddonIndicator" mouseEnabled="true" movable="true" clampedToScreen="true"> <Dimensions x="200" y="25" /> <Anchor point="BOTTOM" relativeTo="GuiRoot" relativePoint="CENTER" offsetY="-20" /> <OnInitialized> -- LUA code here. This is where you'd check to see if the control needs to be hidden or not. RemiCustomAddonIndicator:SetHidden(not (GetNumBagFreeSlots(1) < 10)) </OnInitialized> <OnMoveStop> RemiCustomAddon.OnIndicatorMoveStopBagSpace() </OnMoveStop> <Controls> <Label name="$(parent)Label" width="200" height="25" font="ZoFontWinH1" inheritAlpha="true" color="FFA500" wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER" text="Your bag is almost full!"> <Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" /> </Label> </Controls> </TopLevelControl> </Controls> </GuiXml> |
|
04/30/20, 02:07 AM | #6 |
Could you also show the error message text (complete, expand it to show the error message).
I recommand using LibDebugLogger and DebugLogViewer -> Addon settings of DebugLogViewer -> LiBDebugLogger -> Enable stack trace. It helps showing error message callbacks and watch them later on + creates a SavedVariables file LibDebugLogger.lua which you are able to view / share online here for us: https://sir.insidi.at/or/logviewer/ Share button at the top then to create the link. Try to use and addon like this here to inspect the global variable RemiCustomAddonIndicator. https://www.esoui.com/downloads/info...dImproved.html https://www.esoui.com/downloads/info...oGreymoor.html You can use /tbug (or /tb) RemiCustomAddonIndicator or /zgoo RemiCustomAddonIndicator to inspect it then. Is it available after login and player ready (event_player_activated)? Or does it say in chat: NIL / doesn't zgoo open? |
|
04/30/20, 02:30 AM | #7 | |
Join Date: Apr 2020
Posts: 9
|
Ok i'm going to install your addon to see what I can give you
|
|
04/30/20, 02:37 AM | #8 | |
Join Date: Apr 2020
Posts: 9
|
First error message:
Code:
user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:12: attempt to index a nil value /* <== this line is: RemiCustomAddonIndicator:ClearAnchors() */ stack traceback: user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:12: in function 'RemiCustomAddon:RestorePositionBagSpace' user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:34: in function 'RemiCustomAddon:Initialize' user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:77: in function 'RemiCustomAddon.OnAddOnLoaded' Code:
RemiCustomAddonIndicator:SetHidden(false) Lua Code:
And finally, here is the addon tbug test that you required: "tbug: No inspector for 'RemiCustomAddonIndicator' ("nil") Once again, thank you for your time, and sorry for my replies hours, I currently live in Korea Last edited by EscherechiaColi : 04/30/20 at 02:39 AM. Reason: Added faulty line for error 1 |
|
04/30/20, 02:51 AM | #9 |
Could you please post the TOTAL lua files and do not replace any tetx with [...] as the line numbers of the error mesages do not match your code shown here. It's improtant to see the complete code to see what is run in which order and map it to the errors.
Also if you expand the error messages as they show you can see the variable and table contents. It should show you that the variable is NIL already or at least show you the variables that are not nil, containing there values. This way you are able to see yourself, directly in the lua error message, what is missing/wrong content or value. As RemiCustomAddonIndicator is nil the xml file is either not loaded or loaded after your event_add_on_loaded fires. Change the load order (but you said you already did?) in your txt file maybe before the lua file. Maybe your code in the XML file initialization is causing errors you do not see in chat, so try LibDebugLogger for this! Remove the code in <OnInitialization> of the XML file of the bagspace stuff and try if it works then. Last edited by Baertram : 04/30/20 at 02:55 AM. |
|
04/30/20, 03:28 AM | #10 | |
Join Date: Apr 2020
Posts: 9
|
Sorry... I thought it would be better that way. So here we go:
Lua Code:
As for the error messages, here it is (expanded): Code:
user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:12: attempt to index a nil value stack traceback: user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:12: in function 'RemiCustomAddon:RestorePositionBagSpace' |caaaaaa<Locals> self = [table:1]{inCombat = F, name = "RemiCustomAddon"} </Locals>|r user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:34: in function 'RemiCustomAddon:Initialize' |caaaaaa<Locals> self = [table:1] </Locals>|r user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:77: in function 'RemiCustomAddon.OnAddOnLoaded' |caaaaaa<Locals> event = 65536, addonName = "RemiCustomAddon" </Locals>|r For LibDebugLogger, sorry it took quite a lot of time for me to understand how to use it... Here is the file: https://sir.insidi.at/or/logviewer/NVxFbP As for the .txt file, yes I tried putting .xml files before and after the .lua file, no change. I also already tried removing the OnInitialization code (commenting it with --) to no avail. |
|
04/30/20, 04:03 AM | #11 |
Code:
user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:12: attempt to index a nil value Code:
stack traceback: Code:
user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:12: in function 'RemiCustomAddon:RestorePositionBagSpace' |caaaaaa<Locals> self = [table:1]{inCombat = F, name = "RemiCustomAddon"} </Locals>|r e.g. self = [table:1]{} means self is the first table in the stack traceback and the string between {} is the content of the table. It got a variable inCombat and name inCombat is a variable of your addon's table, which you point to with the self variable. It shows the current value = F (false) / T (true). You can see from that code that in your function RemiCustomAddon:Initialize the variable self.inCombat is false and the self.name "RemiCustomAddon" Code:
user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:34: in function 'RemiCustomAddon:Initialize' |caaaaaa<Locals> self = [table:1] </Locals>|r user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:77: in function 'RemiCustomAddon.OnAddOnLoaded' |caaaaaa<Locals> event = 65536, addonName = "RemiCustomAddon" </Locals>|r About LibDebugLogger: It basically shows the same as the stack trace back above. It only provides a cleaner view of the variables. You can watch the source code you have posted at your LibDebugLogger link. The red lien with the error message. Click it and below you'll see the local variables as parsed "clean view" or raw (like within the error message). I can see you are using several addons, like HarvestMap and others. For the test of your addon you should always disable all other addons and not needed libraries. Reloadui will be much faster then and you can test if your addon alone works, or not. You can use Circonians Addon Selector to create a "addon test" profile and "normal profile" so you are able to switch quickly e.g. Error reason The error happens as your control is NIL: RemiCustomAddonIndicator As the addon tries to access it in the event_add_on_loaded callback function Initialize via your call to RestorePositionBagSpace. Try to move the calls from the initialize function, to RestorePositionBagSpace and RestorePositionCombat to the event_player_activated callback function! It's called later as the chat is ready and all addons were loaded. Event_add_on_loaded also triggers before the UI is ready and might be the problem with the XML control not properly created yet. The benefit: Event_player_activated also fires after a zone change e.g. and would reposition and update the labels. If it also shows an error at event_player_activated your XML might be wrong somehow. Not seeing where though. Edit2 Think I found somehting in your XML file: Code:
<OnInitialized> -- LUA code here. This is where you'd check to see if the control needs to be hidden or not. RemiCustomAddonIndicator:SetHidden(not (GetNumBagFreeSlots(1) < 10)) </OnInitialized> Last edited by Baertram : 04/30/20 at 04:23 AM. |
|
04/30/20, 05:03 AM | #12 | |
Join Date: Apr 2020
Posts: 9
|
Well... I did both the changes that you said could help, and here is what I got
Code:
user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:39: attempt to index a nil value |rstack traceback: user:/AddOns/RemiCustomAddon/RemiCustomAddon.lua:39: in function 'RemiCustomAddon.DoesBagHaveSpace' |caaaaaa<Locals> eventCode = 589824, initial = F </Locals>|r |
|
04/30/20, 05:54 AM | #13 |
Did you try to remove the <OnInit...> handler in the xml file completely to see if it loads properly then?
Not sure what causes this, I can have a look this evening with your code, if you attach the total addon (all files!) as ZIP file e.g. |
|
04/30/20, 09:20 AM | #14 |
|
I think your issue is related to the somewhat confusing process Addons go through while the game is loading. There are a couple key points to consider.
What I usually do to avoid this is to avoid binding to any events from the global space of a LUA file. I instead create an initialize function, then call the initialize function from the <OnInitialized> tags from my xml gui (which then also lets you pass the xml control in to your initialize functions). In your case it would look something like this. xml Code:
Then your initialize function would look like this Lua Code:
That should fix your problem. Edit: Upon review, you may need to add another initialize function to handle the flightIndicator, change the load order of the xml files, or simply combine your two xml files into one. Here is what a combination could look like: xml Code:
This will change the global name bindings, but it also lets you do some nice things in the lua lua Code:
Last edited by Drummerx04 : 04/30/20 at 09:40 AM. |
04/30/20, 09:44 AM | #15 |
Interesting, thanks Drummerx04
Didn't know the EVENT_ADD_ON_LOADED would fire BEFORE actually the XML files are loaded, IF the load order in the txt files woould be Lua Code:
But I wonder why the problem persists if he changed the code from event_add_on_loaded to event_player_activated as at this point all XML and addon code normally was loaded properly, and exists. Not sure why the xml created control would be nil then, at that time |
|
04/30/20, 10:01 AM | #16 | |
|
I was honestly a little surprised that the event appears to fire before the entire addon is initialized, but that is the most logical explanation for the stack track and error he posted originally. |
|
04/30/20, 10:13 AM | #17 |
|
As a new developer, you might also benefit from a standalone addon I wrote a while back. Lilith's Command History
What it does is to provide a history of /script commands executed in ESO which is persistent across UI reloads, support for multi line lua scripts within the game, running/editing commands stored in the list, and it also provides some additional little quality of life changes like a customizable binding for reloading the UI. I think you'd find it pretty helpful. |
04/30/20, 10:24 AM | #18 | |
|
||
04/30/20, 10:30 AM | #19 |
Right, exactly what I thougth and experienced until today.
Not sure what the problem here is but I never had these NIL problems happening if: -txt file order of XML was before lua and no <OnInitialization> tried to access stuff that was inside the lua file -even_player_activated or event_add_on_loaded fired Thats why I asked for the complete source. Perhaps your files use UTF-8 encoding with a ByteOrderMark. Sometimes this freaks out the ingame addon manager, especially if this is set at the addon's txt file! So make sure if utf8 is used the BOM is removed on all txt and lua files. |
|
04/30/20, 10:39 AM | #20 | |
|
If I'm right, then it likely does affect all addons, but authors already have functional workarounds so we don't really notice it. Edit: Also the track record for bug fixes in ESO isn't exactly stellar Edit2: Also he maybe has the wrong xml file name in his .txt so the control is never loaded in the first place. Last edited by Drummerx04 : 04/30/20 at 11:01 AM. |
|
ESOUI » Developer Discussions » Lua/XML Help » Help with XML controls |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|