Quantcast OnUpdate not working. D= - ESOUI
 
Thread Tools Display Modes
07/04/14, 04:59 PM   #1
InfiniteShift
Join Date: Jun 2014
Posts: 4
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)
  Reply With Quote
07/04/14, 05:06 PM   #2
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 241
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)
  Reply With Quote
07/04/14, 05:16 PM   #3
InfiniteShift
Join Date: Jun 2014
Posts: 4
Hmm I was under the impression that OnUpdate is something that got fired every frame.
  Reply With Quote
07/04/14, 05:36 PM   #4
Harven
 
Harven's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 137
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.
  Reply With Quote
07/04/14, 06:17 PM   #5
InfiniteShift
Join Date: Jun 2014
Posts: 4
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)
  Reply With Quote
07/04/14, 07:18 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 651
  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.
  Reply With Quote
07/04/14, 07:56 PM   #7
InfiniteShift
Join Date: Jun 2014
Posts: 4
Originally Posted by Seerah View Post
  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.
  Reply With Quote
07/05/14, 12:33 AM   #8
Sasky
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 241
Originally Posted by Seerah View Post
@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.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » OnUpdate not working. D=

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