Thread Tools Display Modes
12-14-20, 06:00 PM   #1
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
not well-formed error and OnUpdate script not working. Help?

This is the TOC:

UIMod.toc
Lua Code:
  1. ## Interface: 40200
  2. ## Title: UI Modifier
  3. ## Notes: Modifies other addons that change the UI
  4. ## Author: Krainz
  5. ## Version: 1.0
  6.  
  7. core.xml
  8. core.lua

core.lua
Lua Code:
  1. local addon, ns = ...
  2.  
  3. local f = CreateFrame("Frame")
  4.  
  5.  
  6. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  7. f:RegisterEvent("PLAYER_LOGIN");
  8. f:SetScript("OnEvent", function(self, event, ...)
  9.     local garrisonType = C_Garrison.GetLandingPageGarrisonType()
  10.     local covenantID = C_Covenants.GetActiveCovenantID()
  11.     local gwbutton = GwGarrisonButton
  12.     if event == "PLAYER_ENTERING_WORLD" then
  13.         print("UIMOD: Hello! Hello " .. event);
  14.         print(covenantID);
  15.  
  16.         if gwbutton then
  17.             print("UIMOD Entering World: GW2 UI Garrison Button is shown. Hiding.");
  18.             gwbutton:Hide();
  19.         end
  20.  
  21. --      if not covenantID=0 or garrisonType=3 then
  22. --          print("UIMOD: Covenant Chosen or Order Hall enabled.");
  23. --          if gwbutton and gwbutton:IsShown() then
  24. --              print("UIMOD: GW2 UI Garrison Button is shown. Hiding.");
  25. --              gwbutton:Hide();
  26. --          end
  27. --      end
  28.     elseif event == "PLAYER_LOGIN" then
  29.         print("UIMOD: Hello! Hello " .. event);
  30.         print(covenantID);
  31.  
  32.         if gwbutton then
  33.             print("UIMOD Player Login: GW2 UI Garrison Button is shown. Hiding.");
  34.             gwbutton:Hide();
  35.         end
  36.     end
  37. end)
  38.  
  39.  
  40. local UIMod_UpdateInterval = 1.0; -- How often the OnUpdate code will run (in seconds)
  41.  
  42.  
  43. function UIMod_OnUpdate(self, elapsed)
  44.     local gwbutton = GwGarrisonButton
  45.   self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
  46.  
  47.  
  48.   if (self.TimeSinceLastUpdate > UIMod_UpdateInterval) then
  49.     print("UIMOD OnUpdate");
  50.         if gwbutton then
  51.             print("UIMOD OnUpdate: GW2 UI Garrison Button is shown. Hiding.");
  52.             gwbutton:Hide();
  53.         end
  54.     --
  55.  
  56.     self.TimeSinceLastUpdate = 0;
  57.   end
  58. end

core.xml
Lua Code:
  1. <Ui ...>
  2.   <Frame ...>
  3.     ...
  4.     <Scripts>
  5.       <OnLoad>self.TimeSinceLastUpdate = 0 </OnLoad>
  6.       <OnUpdate function="UIMod_OnUpdate" />
  7.     </Scripts>
  8.   </Frame>
  9. </Ui>

I get the following LUA error at login:

Message: Interface\AddOns\UIMod\core.xml(1): error: not well-formed (invalid token)
Time: Mon Dec 14 20:41:58 2020
Count: 3

I also get the following debug messages I set up to make sure each step is working as intended:

08:43:19 | UIMOD: Hello! Hello PLAYER_LOGIN
08:43:19 | 0
08:43:19 | UIMOD Player Login: GW2 UI Garrison Button is shown. Hiding.
08:43:23 | UIMOD: Hello! Hello PLAYER_ENTERING_WORLD
08:43:23 | 0
08:43:23 | UIMOD Entering World: GW2 UI Garrison Button is shown. Hiding.

What happens is: the button doesn't get hidden and the OnUpdate script doesn't seem to be running.

However, if I just type the following:

/script local gwgarrison=GwGarrisonButton if gwgarrison then gwgarrison:Hide(); end
Then the button is properly hidden. I noticed that, however, the GW2 UI addon later on makes the button reappear, which is why the OnUpdate function is important.

Any ideas to what I may be doing wrong?
  Reply With Quote
12-14-20, 07:18 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
The error is with the formatting of your XML, seemingly in line 1.

Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\..\FrameXML\UI.xsd">

</Ui>
should work
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-14-20 at 07:26 PM.
  Reply With Quote
12-14-20, 09:05 PM   #3
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
I tried replacing core.xml to all of the following

Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  2. ..\..\FrameXML\UI.xsd">
  3.   <Frame ...>
  4.     <Scripts>
  5.       <OnLoad>self.TimeSinceLastUpdate = 0 </OnLoad>
  6.       <OnUpdate function="UIMod_OnUpdate" />
  7.     </Scripts>
  8.   </Frame>
  9. </Ui>

Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  2. ..\..\FrameXML\UI.xsd">
  3. </Ui>

Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  2. ..\..\FrameXML\UI.xsd">
  3. </Ui>
  4.   <Frame ...>
  5.     <Scripts>
  6.       <OnLoad>self.TimeSinceLastUpdate = 0 </OnLoad>
  7.       <OnUpdate function="UIMod_OnUpdate" />
  8.     </Scripts>
  9.   </Frame>

Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  2. ..\..\FrameXML\UI.xsd">
  3. </Ui>
  4.   <Frame>
  5.     <Scripts>
  6.       <OnLoad>self.TimeSinceLastUpdate = 0 </OnLoad>
  7.       <OnUpdate function="UIMod_OnUpdate" />
  8.     </Scripts>
  9.   </Frame>

Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
  2. ..\..\FrameXML\UI.xsd">
  3.   <Frame>
  4.     <Scripts>
  5.       <OnLoad>self.TimeSinceLastUpdate = 0 </OnLoad>
  6.       <OnUpdate function="UIMod_OnUpdate" />
  7.     </Scripts>
  8.   </Frame>
  9. </Ui>

And with all of them the onupdate script still doesn't seem to be triggering. What should I do?
  Reply With Quote
12-14-20, 09:41 PM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
Put the OnUpdate in Lua.

Lua Code:
  1. f.TimeSinceLastUpdate = 0
  2.  
  3. f:SetScript("OnUpdate",function(self,elapsed)
  4.     local gwbutton = GwGarrisonButton
  5.   self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
  6.  
  7.  
  8.   if (self.TimeSinceLastUpdate > UIMod_UpdateInterval) then
  9.     print("UIMOD OnUpdate");
  10.         if gwbutton then
  11.             print("UIMOD OnUpdate: GW2 UI Garrison Button is shown. Hiding.");
  12.             gwbutton:Hide();
  13.         end
  14.     --
  15.  
  16.     self.TimeSinceLastUpdate = 0;
  17.   end
  18. end)

Last edited by Kanegasi : 12-15-20 at 02:04 PM. Reason: self to f (oops)
  Reply With Quote
12-14-20, 10:05 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Code:
<OnUpdate> 
        UIMod_OnUpdate(self, elapsed)
</OnUpdate>
Assuming UIMod_OnUpdate is the name of your lua OnUpdate function and it's global.

I would have to check but I'm pretty sure the function attribute came with Mixins and may be tied to them (I don't really use XML these days).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-14-20 at 10:16 PM.
  Reply With Quote
12-14-20, 10:48 PM   #6
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
You are loading the xml before the lua so the function is set to nil. But do as Kanegasi suggested as there is no point in having a separate xml when you are already doing everything in the lua file basically.
  Reply With Quote
12-15-20, 12:13 AM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Fizzlemizz View Post
I would have to check but I'm pretty sure the function attribute came with Mixins and may be tied to them (I don't really use XML these days).
The function attribute assigns a global by name as the script handler. method is the one that takes a table key instead and references whatever mixin(s) you imported.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 12-15-20 at 12:16 AM.
  Reply With Quote
12-15-20, 12:35 AM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Originally Posted by SDPhantom View Post
The function attribute assigns a global by name as the script handler. method is the one that takes a table key instead and references whatever mixin(s) you imported.
Not getting another "not well-formed" error should have been a giveaway. Well, that and reading the .toc listing.

Maybe I'll have better luck next time...
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
12-15-20, 06:43 AM   #9
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
Yeah I used a XML file because the wowwiki article instructed to...

So I shouldn't use XML files when I'm not creating actually graphical UI frames?

Originally Posted by Kanegasi View Post
Put the OnUpdate in Lua.

Lua Code:
  1. self.TimeSinceLastUpdate = 0
  2.  
  3. f:SetScript("OnUpdate",function(self,elapsed)
  4.     local gwbutton = GwGarrisonButton
  5.   self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
  6.  
  7.  
  8.   if (self.TimeSinceLastUpdate > UIMod_UpdateInterval) then
  9.     print("UIMOD OnUpdate");
  10.         if gwbutton then
  11.             print("UIMOD OnUpdate: GW2 UI Garrison Button is shown. Hiding.");
  12.             gwbutton:Hide();
  13.         end
  14.     --
  15.  
  16.     self.TimeSinceLastUpdate = 0;
  17.   end
  18. end)

This is my core.lua now but the OnUpdate funcion still isn't happening. Not even firing the debug prints

Lua Code:
  1. local addon, ns = ...
  2.  
  3. local f = CreateFrame("Frame")
  4.  
  5.  
  6. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  7. f:RegisterEvent("PLAYER_LOGIN");
  8. f:SetScript("OnEvent", function(self, event, ...)
  9.     local garrisonType = C_Garrison.GetLandingPageGarrisonType()
  10.     local covenantID = C_Covenants.GetActiveCovenantID()
  11.     local gwbutton = GwGarrisonButton
  12.     if event == "PLAYER_ENTERING_WORLD" then
  13.         print("UIMOD: Hello! Hello " .. event);
  14.         print(covenantID);
  15.  
  16.         if gwbutton then
  17.             print("UIMOD Entering World: GW2 UI Garrison Button is shown. Hiding.");
  18.             gwbutton:Hide();
  19.         end
  20.  
  21. --      if not covenantID=0 or garrisonType=3 then
  22. --          print("UIMOD: Covenant Chosen or Order Hall enabled.");
  23. --          if gwbutton and gwbutton:IsShown() then
  24. --              print("UIMOD: GW2 UI Garrison Button is shown. Hiding.");
  25. --              gwbutton:Hide();
  26. --          end
  27. --      end
  28.     elseif event == "PLAYER_LOGIN" then
  29.         print("UIMOD: Hello! Hello " .. event);
  30.         print(covenantID);
  31.  
  32.         if gwbutton then
  33.             print("UIMOD Player Login: GW2 UI Garrison Button is shown. Hiding.");
  34.             gwbutton:Hide();
  35.         end
  36.     end
  37. end)
  38.  
  39.  
  40. UIMod_UpdateInterval = 1.0; -- How often the OnUpdate code will run (in seconds)
  41.  
  42.  
  43. self.TimeSinceLastUpdate = 0
  44.  
  45. f:SetScript("OnUpdate",function(self,elapsed)
  46.         local gwbutton = GwGarrisonButton
  47.     self.TimeSinceLastUpdate = self.TimeSinceLastUpdate + elapsed;
  48.  
  49.  
  50.     if (self.TimeSinceLastUpdate > UIMod_UpdateInterval) then
  51.         print("UIMOD OnUpdate");
  52.                 if gwbutton then
  53.                         print("UIMOD OnUpdate: GW2 UI Garrison Button is shown. Hiding.");
  54.                         gwbutton:Hide();
  55.                 end
  56.         --
  57.  
  58.         self.TimeSinceLastUpdate = 0;
  59.     end
  60. end)

I tried removing core.xml from the TOC to no avail

Last edited by Krainz : 12-15-20 at 06:51 AM.
  Reply With Quote
12-15-20, 11:21 AM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
You shouldd be getting an error!
Change the first instance of:
Code:
self.TimeSinceLastUpdate = 0
to:
Code:
f.TimeSinceLastUpdate = 0
f is the frame you just created. The second place you reset self.TimeSinceLastUpdate is the frame referring to itself inside the script.

XML in WoW is used for frame creation and not much else (but that can also be done in lua alone).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 12-15-20 at 11:26 AM.
  Reply With Quote
12-15-20, 07:33 PM   #11
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
It worked!!!!!!!! Thanks!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » not well-formed error and OnUpdate script not working. Help?

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