Wowpedia

We have moved to Warcraft Wiki. Click here for information and the new URL.

READ MORE

Wowpedia
Advertisement

Invoked when drawing the user interface (many times per second).

(self, elapsed)

Payload[]

self
ScriptObject - The updated widget.
elapsed
number - The time in seconds since the last OnUpdate dispatch, but excluding time when the user interface was not being drawn such as while zoning into the game world[citation needed] 

Details[]

  • Preceeded by handlers associated with processing user input.
  • Blocked by hiding a frame or its parent.
  • OnUpdate is resource intensive because it fires as often as the client can draw new frames -- potentially hundreds of FPS with modern computers.
    • It is usually better to substitute C_Timer.After() or C_Timer.NewTicker() to skip frames, or to apply an Animation for animating a widget.
    • Alternatively, throttle slower parts of an OnUpdate handler by measuring the passage of time and only performing work as often as reasonably necessary.

Examples[]

Throttles a workload no more than once every 0.05 seconds:

local frame = CreateFrame("FRAME")
local timeElapsed = 0
frame:HookScript("OnUpdate", function(self, elapsed)
	timeElapsed = timeElapsed + elapsed
	if timeElapsed > 0.05 then
		timeElapsed = 0
		-- do something
	end
end)

Executes a workload 20 times per second. If FPS is slower than 20, the workload repeats until caught up.

local frame = CreateFrame("FRAME")
local timeElapsed = 0
frame:HookScript("OnUpdate", function(self, elapsed)
	timeElapsed = timeElapsed + elapsed
	while (timeElapsed > 0.05) do
		timeElapsed = timeElapsed - 0.05
		-- do something
	end
end)
Advertisement