View Single Post
02-02-08, 03:59 PM   #19
mulesh
A Chromatic Dragonspawn
 
mulesh's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2006
Posts: 193
Change it to this and see if it pops up any messages:
Code:
local frame= CreateFrame("Frame")
frame:RegisterEvent("PLAYER_AURAS_CHANGED")
frame:SetScript("OnEvent", function(frame)
    local t = 0
    frame:SetScript("OnUpdate", function(_, elapsed)
        t = t + elapsed
        if t >= 1 then
            frame:SetScript("OnUpdate", nil) 
            if IsMounted() then
                PlayMusic("Interface\\AddOns\\OnTheRoad\\music.mp3")
                DEFAULT_CHAT_FRAME:AddMessage("Playing music")
            else  
                StopMusic()
                DEFAULT_CHAT_FRAME:AddMessage("Stopping music")
            end
        end
end)
To answer your question, the OnUpdate script is called by the game every time the screen refreshes (i.e. 30fps means 30 calls per second). The "elapsed" variable is a value for how much time has passed since the last OnUpdate call. Setting the timer to zero (local t = 0) and then we keep adding the value of "elapsed" to it (t = t + elapsed) until the timer equals 1 second or more (t >= 1). Once it equals 1 or more seconds we check if the player is mounted or not. By changing the t >= 1 line to something like t >= 2 would cause it to check for player mount every 2 seconds.

Not to put a stopper to your learning experience, but you could just use my PlaySound addon (shameless plug, whoohoo!!).

Good luck dood
__________________
"Don"t tase me bro!" ~ Andrew Meyer
  Reply With Quote