View Single Post
08-21-14, 08:29 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
For now, you need to create a frame that'll run the code in its OnUpdate handler.
lua Code:
  1. local lastupdate=0;--   Local storing how long since our last update
  2. local frame=CreateFrame("Frame");-- Our frame
  3.  
  4. frame:SetScript("OnUpdate",function(self,elapsed)
  5.     lastupdate=lastupdate+elapsed;--    Add elapsed to update local
  6.     if lastupdate>1 then--  If it's been a second, update
  7.         AgilityLine.text:SetText("Agility = ".. getRangedAgility());
  8.         AttackPowerLine.text:SetText("AP = ".. getRangedAttackPower());
  9.         CritLine.text:SetText("Crit = ".. getRangedCrit() .."%");
  10.         MasteryLine.text:SetText("Mastery = ".. getRangedMastery());
  11.         HasteLine.text:SetText("Haste = ".. getHaste() .."%");
  12.  
  13.         lastupdate=0;-- Reset to zero
  14.     end
  15. end);



In WoD, we'll be getting a new C_Timer system to handle this.
When this happens, your code would look like this.
lua Code:
  1. C_Timer.NewTicker(1,function()--    Register a function to update every second
  2.     AgilityLine.text:SetText("Agility = ".. getRangedAgility());
  3.     AttackPowerLine.text:SetText("AP = ".. getRangedAttackPower());
  4.     CritLine.text:SetText("Crit = ".. getRangedCrit() .."%");
  5.     MasteryLine.text:SetText("Mastery = ".. getRangedMastery());
  6.     HasteLine.text:SetText("Haste = ".. getHaste() .."%");
  7. end);



Note: To enable Lua syntax highlighting on these forums, surround the code with [highlight=lua] [/highlight].
This is also visible as a Lua button on the right side of the formatting toolbar in the message editor.
__________________
WoWInterface AddOns
"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-21-14 at 08:39 PM.
  Reply With Quote