Reply
Thread Tools Display Modes
Unread 08-04-14, 09:38 AM   #1
citrot
A Murloc Raider
Join Date: Jul 2014
Posts: 5
Function timing

Hi!

I would like to execute timed functions. Only wow lua support i found until now: "OnUpdate" event. Is there something else what is not based on graphical engine?

Thank you,
citrot is offline   Reply With Quote
Unread 08-04-14, 12:19 PM   #2
Phanx
A Pyroguard Emberseer
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 4,751
Unless you're getting 2 FPS, and even then for most purposes, it doesn't really matter that OnUpdate is tied to your framerate:

Code:
local t = 5 -- do something 5 seconds from now
local f = CreateFrame("Frame")
f:SetScript("OnUpdate", function(self, elapsed)
     t = t - elapsed
     if t <= 0 then
          -- do something
     end
end)
Your other option would be to use the animation system:

Code:
local f = CreateFrame("Frame")
local g = f:CreateAnimationGroup()
local a = g:CreateAnimation()
a:SetDuration(5) -- do something in 5 seconds
g:SetScript("OnFinished", function()
     -- do something
end)
All existing timer libraries use one of the above methods.

In WoD the game will provide an actual timer mechanism, but the primary benefit to using it will likely be in reducing the amount of code that needs to be written to implement a timer, rather than offering any tangible performance boost:

Code:
C_Timer.After(5, function()
     -- do something
end)
__________________
Author/maintainer of Grid, PhanxChat, ShieldsUp, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!
Phanx is offline   Reply With Quote
Unread 08-04-14, 07:12 PM   #3
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,320
C_Timer would most likely be better for performance too, but no benchmarks have been done yet.
p3lim is offline   Reply With Quote
Unread 08-04-14, 09:17 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,090
I would think C_Timer.After() would be easier on resources since you won't have to create any UI objects to use. The only problem is you'll need to manage setting it up again if you want something to keep calling every so many seconds if you don't want to use Blizzard's Lua-defined Ticker factories (C_Timer.NewTicker() and C_Timer.NewTimer()). Note the Ticker factories return a table hooked into a metatable to control the ability to cancel a timer with entries for remaining iteration counts, a cancel flag, and a dynamicly-created callback function that is passed to C_Timer each iteration. This creates significantly more overhead than using C_Timer.After() yourself.
__________________
"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 : 08-04-14 at 09:36 PM.
SDPhantom is offline   Reply With Quote
Unread 08-04-14, 11:51 PM   #5
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,320
Originally Posted by SDPhantom View Post
I would think C_Timer.After() would be easier on resources since you won't have to create any UI objects to use. The only problem is you'll need to manage setting it up again if you want something to keep calling every so many seconds if you don't want to use Blizzard's Lua-defined Ticker factories (C_Timer.NewTicker() and C_Timer.NewTimer()). Note the Ticker factories return a table hooked into a metatable to control the ability to cancel a timer with entries for remaining iteration counts, a cancel flag, and a dynamicly-created callback function that is passed to C_Timer each iteration. This creates significantly more overhead than using C_Timer.After() yourself.
Basically, unless you need to cancel it or need something that keeps repeating, use C_Timer.After.
p3lim is offline   Reply With Quote
Unread 08-05-14, 03:54 PM   #6
citrot
A Murloc Raider
Join Date: Jul 2014
Posts: 5
Thank you for tipps. I think, i keep OnUpdate.
citrot is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » General Authoring Discussion » Function timing

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