View Single Post
04/30/20, 09:20 AM   #14
Drummerx04
AddOn Author - Click to view addons
Join Date: Sep 2017
Posts: 54
Post

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.
  • Each xml element of your code has to be instantiated before you make a call to it, otherwise it will be nil
  • Your files get loaded in the order present in the .txt manifest file (which looks fine for your purposes)
  • When a file is loaded, all lua/xml code is processed and run at that point. This is usually safe for variable and function declarations only.
  • Your RemiCustomAddon.lua binds your addon to EVENT_ADD_ON_LOADED before all of your elements are actually initialized. Since this is done in the global code area, this happens before your xml has been processed
  • ESO is then calling your OnAddonLoaded() function before processing the xml files.

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:
  1. <GuiXml>
  2.   <Controls>
  3.     <TopLevelControl name="RemiCustomAddonIndicator" mouseEnabled="true" movable="true" clampedToScreen="true">
  4.       <Dimensions x="200" y="25" />
  5.       <Anchor point="BOTTOM" relativeTo="GuiRoot" relativePoint="CENTER" offsetY="-20" />
  6.       <OnInitialized>
  7.           -- Call your initialize function from here
  8.           RemiCustomAddon:Initialize(self)
  9.       </OnInitialized>
  10.       <OnMoveStop>
  11.         RemiCustomAddon.OnIndicatorMoveStopBagSpace()
  12.       </OnMoveStop>
  13.  
  14.       <Controls>
  15.         <Label name="$(parent)Label" width="200" height="25" font="ZoFontWinH1" inheritAlpha="true" color="FFA500"
  16.            wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER" text="Your bag is almost full!">
  17.           <Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" />
  18.         </Label>
  19.       </Controls>
  20.     </TopLevelControl>
  21.   </Controls>
  22. </GuiXml>

Then your initialize function would look like this
Lua Code:
  1. function RemiCustomAddon:Initialize(control)
  2.     -- control -> RemiCustomAddonIndicator
  3.     self.inCombat = IsUnitInCombat("player");
  4.    
  5.  
  6.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_COMBAT_STATE, self.OnPlayerCombatState)
  7.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_GROUPING_TOOLS_READY_CHECK_UPDATED, self.OnLFGReadyCheckState)
  8.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_ACTIVATED, self.DoesBagHaveSpace)
  9.  
  10.     -- Bind the addon load from here.
  11.     EVENT_MANAGER:RegisterForEvent(RemiCustomAddon.name, EVENT_ADD_ON_LOADED, RemiCustomAddon.OnAddOnLoaded)
  12.  
  13.     -- Shouldn't need this call because you also bound it to PLAYER_ACTIVATED, but I included it because you had it in the xml originally
  14.     self.DoesBagHaveSpace()
  15.     self.savedVariables = ZO_SavedVars:New("RemiCustomAddonSavedVariables", 1, nil, {})
  16.     self:RestorePositionBagSpace()
  17.     self:RestorePositionFight()
  18. end

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:
  1. <GuiXml>
  2.   <Controls>
  3.     <TopLevelControl name="RemiCustomAddonIndicators" mouseEnabled="true" movable="true" clampedToScreen="true">
  4.       <Dimensions x="200" y="25" />
  5.       <Anchor point="BOTTOM" relativeTo="GuiRoot" relativePoint="CENTER" offsetY="-20" />
  6.       <OnInitialized>
  7.           -- Call your initialize function from here
  8.           RemiCustomAddon:Initialize(self)
  9.       </OnInitialized>
  10.       <OnMoveStop>
  11.         RemiCustomAddon.OnIndicatorMoveStopBagSpace()
  12.       </OnMoveStop>
  13.  
  14.       <Controls>
  15.     <Control name="BagIndicator" mouseEnabled="true" movable="true" clampedToScreen="true">
  16.       <Dimensions x="200" y="25" />
  17.       <Anchor point="BOTTOM" relativeTo="GuiRoot" relativePoint="CENTER" offsetY="-20" />
  18.       <OnMoveStop>
  19.             RemiCustomAddon.OnIndicatorMoveStopBagSpace()
  20.       </OnMoveStop>
  21.       <Controls>
  22.         <Label name="$(parent)Label" width="200" height="25" font="ZoFontWinH1" inheritAlpha="true" color="FFA500"
  23.            wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER" text="Your bag is almost full!">
  24.               <Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" />
  25.             </Label>
  26.       </Controls>
  27.     </Control>
  28.    
  29.     <Control name="FightIndicator" mouseEnabled="true" movable="true" clampedToScreen="true">
  30.       <Dimensions x="200" y="25" />
  31.       <Anchor point="BOTTOM" relativeTo="GuiRoot" relativePoint="CENTER" offsetY="-20" />
  32.       <OnMoveStop>
  33.             RemiCustomAddon.OnIndicatorMoveStopFight()
  34.       </OnMoveStop>
  35.       <Controls>
  36.             <Label name="$(parent)Label" width="200" height="25" font="ZoFontWinH1" inheritAlpha="true" color="FF0000"
  37.            wrapMode="TRUNCATE" verticalAlignment="TOP" horizontalAlignment="CENTER" text="Fighting!">
  38.               <Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" />
  39.             </Label>
  40.       </Controls>
  41.     </Control>
  42.       </Controls>
  43.     </TopLevelControl>
  44.   </Controls>
  45. </GuiXml>

This will change the global name bindings, but it also lets you do some nice things in the lua
lua Code:
  1. function RemiCustomAddon:Initialize(control)
  2.     -- You can now grab child elements of your top level control without worrying about the full global names.
  3.     local bagIndicator = GetControl(control, "BagIndicator");
  4.     local fightIndicator = GetControl(control, "FightIndicator");
  5.  
  6.     --You can also do this
  7.     GetControl(bagIndicator, "Label"):SetText("Now your label text has changed")
  8.  
  9.  
  10.     self.inCombat = IsUnitInCombat("player");
  11.    
  12.  
  13.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_COMBAT_STATE, self.OnPlayerCombatState)
  14.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_GROUPING_TOOLS_READY_CHECK_UPDATED, self.OnLFGReadyCheckState)
  15.     EVENT_MANAGER:RegisterForEvent(self.name, EVENT_PLAYER_ACTIVATED, self.DoesBagHaveSpace)
  16.  
  17.     -- Bind the addon load from here.
  18.     EVENT_MANAGER:RegisterForEvent(RemiCustomAddon.name, EVENT_ADD_ON_LOADED, RemiCustomAddon.OnAddOnLoaded)
  19.  
  20.     -- Shouldn't need this call because you also bound it to PLAYER_ACTIVATED, but I included it because you had it in the xml originally
  21.     self.DoesBagHaveSpace()
  22.     self.savedVariables = ZO_SavedVars:New("RemiCustomAddonSavedVariables", 1, nil, {})
  23.     self:RestorePositionBagSpace()
  24.     self:RestorePositionFight()
  25. end

Last edited by Drummerx04 : 04/30/20 at 09:40 AM.
  Reply With Quote