View Single Post
12/23/15, 08:17 AM   #1
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,580
Bug with EVENT_UNIT_CREATED and GetUnit*

I tried to get the unit name of newly joined group members and found that it does not work as expected.
Here is the code I tested it with:
Lua Code:
  1. EVENT_MANAGER:RegisterForEvent("nametest", EVENT_UNIT_CREATED, function(_, unitTag)
  2. df("unit created: %s %s (%s)", tostring(unitTag), GetUnitDisplayName(unitTag), tostring(DoesUnitExist(unitTag)))
  3. end)

When I make a new group, I get one EVENT_UNIT_CREATED for myself which is fine, but for some reason I get two events for whoever I invited. Besides that everything works fine in all three events.
Code:
unit created: group1 @sirinsidiator (true)
unit created: group2 @groupie1 (true)
unit created: group2 @groupie1 (true)
But when I invite another player, the first occurrence returns an empty name and only the second one works as expected.
Code:
unit created: group3  (true)
unit created: group3 @groupie2 (true)
DoesUnitExist does not help as it always returns true, so the only thing I can do is check for an empty string and ignore those events.
  Reply With Quote