WoW:Using OnUpdate correctly
Jump to navigation
Jump to search
first of all you have to have a main frame where you define the onUpdate function that will be called on every update. it is important, that this frame has the tags stated below ... hidden="false" toplevel="true", otherwise your function will not be called
this is in your XML file.
<Frame name="MyAddon_MainFrame" parent="UIParent" hidden="false" toplevel="true"> <Frames> </Frames> <Scripts> <OnUpdate> MyAddon_OnUpdate(arg1); </OnUpdate> </Scripts> </Frame>
this is in your LUA file
MyAddon_LastUpdate = 0; MyAddon_Update_Interval = 1; --the update interval in seconds
function MyAddon_OnUpdate(elapsed) MyAddon_LastUpdate = MyAddon_LastUpdate + elapsed; if (MyAddon_LastUpdate > MyAddon_Update_Interval) then MyAddon_LastUpdate = 0; --do Stuff here end end
for '--do stuff here' you should insert your own sourcecode that should be run every 'MyAddon_Update_Interval' seconds. of course you should replace all function / variable names ( MyAddon_ ) with a unique string representing your addon.