Thanks everybody for the extra pointers, I'm very grateful! Seerah, here is my complete code right now (pardon how ugly my button looks, i'm planning to pretty it up once it all works. I also plan to find the aura by name in that if statement, not just by only having ten seconds remaining.) I put all the suggestions in, to my best ability - it's not working but I'm certain that's just because of a rookie error on my end.
Lua Code:
local button = CreateFrame("Button", "myMacroButton", UIparent, "SecureActionButtonTemplate")
frame:RegisterEvent("UNIT_AURA");
local function timeleft(self, event, ...)
frame.TimeToCheck = 1 -- check buff timers every second
frame:SetScript("OnUpdate", function(self, elapsed)
self.TimeToCheck = self.TimeToCheck - elapsed
if self.TimeToCheck > 0 then
return -- We haven't counted down to zero yet so do nothing
end
self.TimeToCheck = 1 -- We've waited a second so reset the timer
for i=1,40 do
local aura.name, aura.icon, aura.count, aura.type, aura.max_time, aura.end_time, aura.caster, aura.is_stealable = UnitAura("player", i);
if aura.max_time and aura.max_time > 0 then
aura.start_time = aura.end_time - aura.max_time;
elseif aura.end_time and aura.end_time > 0 then
aura.start_time = GetTime();
aura.max_time = aura.end_time - aura.start_time;
else
aura.max_time = nil;
aura.start_time = nil;
aura.end_time = nil;
end
return aura.end_time - aura.start_time
if timeleft <= 10 then
print "test"
popup()
end
end
end
end
end)
local function popup()
button:Show()
PlaySound(1221)
FlashClientIcon()
button:SetAttribute("type1", "macro") -- left click causes macro
button:SetAttribute("macrotext1", "/cast Reflecting Prism")
button:SetPoint("CENTER", mainframe, "CENTER", 0, 0)
button:SetText("Your Reflecting Prism will expire in 1 minute.")
button:SetNormalFontObject("GameFontNormalSmall")
button:SetNormalTexture("Interface/Icons/Inv_jewelcrafting_prism")
button:SetHighlightTexture("Interface/ICONS/Spell_nature_wispsplode")
button:SetPushedTexture("Interface/Icons/Spell_nature_wispsplode")
button:SetAttribute("type", "spell")
button:SetAttribute("spell", spell)
button:SetPoint('CENTER')
button:SetSize(30, 30)
button:EnableMouse(true)
button:RegisterForClicks("LeftButtonUp")
button:SetScript("PostClick", function(self, arg1)
print "x"
button:Hide()
button:SetParent(nil)
end)
end