Originally Posted by Phanx
Yes, your example is exactly how it worked before RegisterUnitEvent was introduced in MoP.
However, based on the event you chose as an example, I think you may be confused about what RegisterUnitEvent does. "Unit events" are events whose names start with "UNIT_" and whose first argument is a unit token. PLAYER_SPECIALIZATION_CHANGED is not a "unit event", so you can't use RegisterUnitEvent with it anyway. In your example code, your event handler would never actually do anything, because the first argument for PLAYER_SPECIALIZATION_CHANGED is not a unit token; actually, it's not anything, since PLAYER_SPECIALIZATION_CHANGED doesn't fire with any arguments. You would only use RegisterUnitEvent for events like UNIT_AURA or UNIT_HEALTH. For all other events, you just use RegisterEvent.
On a side note, if you're already using a dedicated function for each event, there's no reason to use a vararg (...). It just makes your code harder to read (and adds some so-small-as-to-be-mostly-just-theoretical overhead). You know what arguments the event will receive, so just name them directly in the function definition:
Code:
function MyAddOn:UNIT_SPELLCAST_START(event, unit, spellName, spellRank, lineID, spellID)
if unit == "player" then
end
end
|
Hi Phanx,
Thank you so much for your clarification!
I thought that every single events in WoW can be registered as a unit specific event D:...
Now I won't make the same mistake
Thank you again!!