WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   not well-formed error and OnUpdate script not working. Help? (https://www.wowinterface.com/forums/showthread.php?t=58462)

Krainz 12-14-20 06:00 PM

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:

Quote:

/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?

Fizzlemizz 12-14-20 07:18 PM

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

Krainz 12-14-20 09:05 PM

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?

Kanegasi 12-14-20 09:41 PM

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)

Fizzlemizz 12-14-20 10:05 PM

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).

Vrul 12-14-20 10:48 PM

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.

SDPhantom 12-15-20 12:13 AM

Quote:

Originally Posted by Fizzlemizz (Post 337925)
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.

Fizzlemizz 12-15-20 12:35 AM

Quote:

Originally Posted by SDPhantom (Post 337928)
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...

Krainz 12-15-20 06:43 AM

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?

Quote:

Originally Posted by Kanegasi (Post 337924)
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

Fizzlemizz 12-15-20 11:21 AM

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).

Krainz 12-15-20 07:33 PM

It worked!!!!!!!! Thanks!


All times are GMT -6. The time now is 02:59 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI