Skip to content

Instantly share code, notes, and snippets.

@Choonster
Created January 9, 2015 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Choonster/eb07bbd750776d1254fc to your computer and use it in GitHub Desktop.
Save Choonster/eb07bbd750776d1254fc to your computer and use it in GitHub Desktop.
An example of OnUpdate throttling in WoW.
local frame = CreateFrame("Frame")
-- The minimum number of seconds between each update
local ONUPDATE_INTERVAL = 0.1
-- The number of seconds since the last update
local TimeSinceLastUpdate = 0
frame:SetScript("OnUpdate", function(self, elapsed)
TimeSinceLastUpdate = TimeSinceLastUpdate + elapsed
if TimeSinceLastUpdate >= ONUPDATE_INTERVAL then
TimeSinceLastUpdate = 0
-- Do stuff
end
end)
-- When the frame is shown, reset the update timer
frame:SetScript("OnShow", function(self)
TimeSinceLastUpdate = 0
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment