For now, you need to create a frame that'll run the code in its OnUpdate handler.
lua Code:
local lastupdate=0;-- Local storing how long since our last update
local frame=CreateFrame("Frame");-- Our frame
frame:SetScript("OnUpdate",function(self,elapsed)
lastupdate=lastupdate+elapsed;-- Add elapsed to update local
if lastupdate>1 then-- If it's been a second, update
AgilityLine.text:SetText("Agility = ".. getRangedAgility());
AttackPowerLine.text:SetText("AP = ".. getRangedAttackPower());
CritLine.text:SetText("Crit = ".. getRangedCrit() .."%");
MasteryLine.text:SetText("Mastery = ".. getRangedMastery());
HasteLine.text:SetText("Haste = ".. getHaste() .."%");
lastupdate=0;-- Reset to zero
end
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:
C_Timer.NewTicker(1,function()-- Register a function to update every second
AgilityLine.text:SetText("Agility = ".. getRangedAgility());
AttackPowerLine.text:SetText("AP = ".. getRangedAttackPower());
CritLine.text:SetText("Crit = ".. getRangedCrit() .."%");
MasteryLine.text:SetText("Mastery = ".. getRangedMastery());
HasteLine.text:SetText("Haste = ".. getHaste() .."%");
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.