It seems you already got some help, but I thought it'd be good to really explain what's going on here. You know, teach a man to fish.
Originally Posted by
Darsyek
Code:
( UnitClassification("target") == "normal" or "trivial" or "minus" )
That expression can only be evaluated to true (boolean value) or "trivial" (string), which is then evaluated to true as a boolean expression by the if-statement. In other words the if statement is equivalent to this:
First it evaluates
Code:
UnitClassification("target") == "normal"
Which is either true or false. If it's true, then the whole expression is true. If it's false, then what has to be evaluated is this:
Code:
false or "trivial" or "minus"
In lua or will always pass forward the first non-false value from left to right. For example:
(4 or 5 or 6) is evaluated to 4
(nil or "hello") is evaluated to "hello"
(true or "hello") is evaluated to true
As such (false or "trivial" or "minus") is evaluated to "trivial". The if-statement treats this as a boolean expression, and in lua everything other than nil or false is evaluated to true.
I'm almost certain that WeakAuras checks the trigger with something like this:
Code:
if (YourTriggerFunction()) then
-- Do stuff
end
So going by what I explained earlier about how lua evaluates boolean expressions, any return value other than nil or false should work, but the convention is to just return true.
Also, I'm pretty sure "trivial" isn't a possible return value for UnitClassification. You need to use UnitIsTrivial for that.
Finally, UnitClassification seems to return "normal" when there is no target selected, so you need to check UnitExists("target"), too.
I think this is what you were trying to write:
Code:
-- trigger
function()
local classification = UnitClassification("target")
if (UnitExists("target") and (classification == "normal" or classification == "minus" or UnitIsTrivial("target"))) then
return true
end
end
--untrigger
function()
local classification = UnitClassification("target")
if not (UnitExists("target") and (classification == "normal" or classification == "minus" or UnitIsTrivial("target"))) then
return true
end
end
PS. Something you might want to do for testing is printing stuff to see what's going on. If you add print("hello") in your trigger before returning true, you will see in your chat box when the trigger returns true, so you get some idea about whether the problem is in the trigger or somewhere else. Even better, you can even see what your expression evaluates to by doing something like this:
Code:
function()
local test = UnitClassification("target") == "normal" or "trivial" or "minus"
print(test)
if test then
return true
end
end