12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 18 ■ Responding to Graphic Updates with OnUpdate 357endendCombatTracker_UpdateText()counter = 0Finally, you should set the OnUpdate script when the player enters combat,<strong>and</strong> clear it when the player leaves combat. Under the PLAYER_REGEN_ENABLEDcondition in CombatTracker_OnEvent(), add the following:frame:SetScript(“OnUpdate“, nil)Within the PLAYER_REGEN_DISABLED condition, add this line:frame:SetScript(“OnUpdate“, CombatTracker_OnUpdate)Now as long as you are in combat the calculation will be updated everysecond.Considering Per<strong>for</strong>mance with OnUpdate ScriptsRemember that the code in your OnUpdate h<strong>and</strong>ler is called on every screenupdate. If the screen refreshes at 60 frames per second, then your script willbe called 60 times per second. As a result you should be sure to considerper<strong>for</strong>mance when writing your functions. Don’t over-scrutinize your codeinto some monster, but be aware that a poorly written OnUpdate script can affectthe frame rate <strong>of</strong> the client. In particular you should consider the following:The game client runs code sequentially. As a result, all OnUpdate scripts arerun be<strong>for</strong>e the client continues to process events or update the graphics.If your function does not need to run every screen refresh, you can use athrottle to introduce a delay.Local variables are faster than global variables, so you can squeeze out abit <strong>of</strong> extra per<strong>for</strong>mance by using them.SummaryThis chapter discussed using OnUpdate scripts to introduce delays or run codeperiodically. You created a number <strong>of</strong> small addons that use OnUpdate scriptsto per<strong>for</strong>m various tasks.The next chapter introduces you to function hooking, <strong>and</strong> using a combination<strong>of</strong> an OnUpdate timer <strong>and</strong> function hooking to alter the default userinterface.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!