View Single Post
10-10-16, 03:27 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
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
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 10-10-16 at 03:33 AM.
  Reply With Quote