Reputation: 193
I'm trying to create an addon for World of Warcraft. I have created a function that checks whether a buff has been added to the current player.
Button:RegisterEvent("UNIT_AURA");
local function auraGained(self, event, ...)
if (UnitAura("player", "Heating Up")) then
if (heatingUpIsActive ~= 1) then
heatingUpIsActive = heatingUpIsActive + 1
print (heatingUpIsActive)
end
end
Button:SetScript("OnEvent", auraGained);
This works great, but how do I check if UnitAura
is not "Heating Up"
?
Also, I would prefer if heatingUpIsActive
were a boolean
, but it seems to not like when I do that. What is the correct way to create a boolean
in Lua?
Upvotes: 1
Views: 4861
Reputation: 185663
Your function isn't checking the aura that caused the event. It's looking for "Heating Up" any time any UNIT_AURA
event comes by. In fact, it looks like the UNIT_AURA
event doesn't actually tell you which aura triggered it. So you can't "check if UnitAura
is not "Heating Up"
", because you simply don't know what aura caused the event. Perhaps it was even several auras at once.
However, the event does tell you what unit got the aura. It's the first vararg. You should probably check to make sure it's player
before doing something
local unitid = ...
if unitid ~= "player" then return end
Also, you didn't explain what problems you had with booleans. You should just be able to say something like
if not heatingUpIsActive then
heatingUpIsActive = true
-- do whatever you want
end
although I never saw any declaration of the variable in your code. It's a bad idea to use globals for things like this, so you should declare
local heatingUpIsActive
before the function declaration, e.g.
local heatingUpIsActive
local function auraGained(self, event, ...)
-- ...
Upvotes: 3