ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   OnUpdate not working. D= (https://www.esoui.com/forums/showthread.php?t=1905)

InfiniteShift 07/04/14 04:59 PM

OnUpdate not working. D=
 
At the moment I'm just fiddling around, trying to set up a basic clock. I'm unsure of what I'm doing wrong here.

lua Code:
  1. tkClock = tkUI.CreateText("tkClock", Guiroot) --CT_LABEL
  2. tkClock:SetAnchor(TOPRIGHT,Guiroot,TOPRIGHT,-10,-5)
  3. tkClock:SetHandler("OnUpdate", function()
  4.   tkClock:SetText(GetTimeString())
  5. end)

Sasky 07/04/14 05:06 PM

I think that OnUpdate would fire whenever your text field itself is updated. To have something update the clock periodically, try:

Lua Code:
  1. EVENT_MANAGER:RegisterForUpdate("tkClockUpdate", 1000, function()
  2.     tkClock:SetText(GetTimeString())
  3. end))

This will cause it to update text once per second (which is honestly all you really need to do for a clock)

InfiniteShift 07/04/14 05:16 PM

Hmm I was under the impression that OnUpdate is something that got fired every frame.

Harven 07/04/14 05:36 PM

Hey,
Your code should work, but make sure that the tkClock is visible (tkClock:SetHidden(false)). OnUpdate will not fire when the control is hidden.

InfiniteShift 07/04/14 06:17 PM

It's not hidden. I added a few things to make sure.

lua Code:
  1. tkClock = tkUI.CreateText("tkClock", Guiroot) --CT_LABEL
  2. tkClock:SetAnchor(TOPRIGHT,Guiroot,TOPRIGHT,-10,-5)
  3. tkClock:SetText("loaded") --To see if tkClock not hidden
  4. tkClock:SetHidden(false)
  5. tkClock:SetHandler("OnUpdate", function()
  6.   tkClock:SetText(GetTimeString())
  7. end)

Seerah 07/04/14 07:18 PM

  1. It's GuiRoot, not Guiroot.
  2. I don't recall 100%, but you may need to use the OnUpdate on a frame, not just on a label.
  3. There was a bug back in beta that I don't think ever got fixed - your frame will not recognize an OnUpdate handler unless the frame was created via XML. (Try Sasky's method instead, or switch to XML - you're giving your frame a global name anyway.)

@Sasky: OnUpdate fires for every update of the UI (every frame draw).

@InfiniteShift: Because of the above, if you have 60 fps, your OnUpdate script will be run 60 times per second. You don't need your clock to be that precise. Use the second return from OnUpdate (or set a delay using the second arg of EVENT_MANAGER:RegisterForUpdate) to create a buffer.

InfiniteShift 07/04/14 07:56 PM

Quote:

Originally Posted by Seerah (Post 10179)
  1. It's GuiRoot, not Guiroot.
  2. I don't recall 100%, but you may need to use the OnUpdate on a frame, not just on a label.
  3. There was a bug back in beta that I don't think ever got fixed - your frame will not recognize an OnUpdate handler unless the frame was created via XML. (Try Sasky's method instead, or switch to XML - you're giving your frame a global name anyway.)

@Sasky: OnUpdate fires for every update of the UI (every frame draw).

@InfiniteShift: Because of the above, if you have 60 fps, your OnUpdate script will be run 60 times per second. You don't need your clock to be that precise. Use the second return from OnUpdate (or set a delay using the second arg of EVENT_MANAGER:RegisterForUpdate) to create a buffer.

I was more or less trying to get the OnUpdate script to just work rather than being optimized.
So all frames not created by XML will not work with the OnUpdate handler? I guess that won't really matter with RegisterForUpdate in the event manager. Anyway, thanks.

Sasky 07/05/14 12:33 AM

Quote:

Originally Posted by Seerah (Post 10179)
@Sasky: OnUpdate fires for every update of the UI (every frame draw).

Got it. Never messed with every frame update since it's not really needed for most things.


All times are GMT -6. The time now is 11:48 PM.

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