Thread Tools Display Modes
09-18-18, 07:56 PM   #1
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 46
Why does RegisterUnitEvent responds to all units if the unit parameter is set to nil?

How's everyone going?!

So, the title says pretty much all.

Why does RegisterUnitEvent responds to all units if the unit parameter is set to nil?

I currently have the following code.

Lua Code:
  1. if info.event then
  2.     for event, unit in pairs(info.event) do
  3.         if type(unit) == "table" then
  4.             object:RegisterUnitEvent(event, unit[1], unit[2]);
  5.         else
  6.             object:RegisterEvent(event);
  7.         end
  8.     end
  9.  
  10.     object:SetScript("OnEvent", function(self, event, ...)
  11.         prototype[event](self, info, ...);
  12.     end);
  13. end

This will make an object respond to all units if unit[2] is nil.

Why...?

I could just make an extra if statement to check if unit[2] exists, but before that I really want to know what's the difference between leaving the second unit parameter empty and assigning nil?
  Reply With Quote
09-18-18, 09:03 PM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
RegisterUnitEvent looks for unitIDs, which are strings. "player", "target", "boss1", "raid9", etc. What you are passing is a table, which means it probably has a fallback to a valid unitID, or string.
  Reply With Quote
09-18-18, 09:27 PM   #3
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
As long as the table has at least one entry then this should work:
Code:
object:RegisterUnitEvent(event, unpack(unit))
  Reply With Quote
09-18-18, 09:36 PM   #4
Lyak
A Cyclonian
Join Date: Jul 2018
Posts: 46
Originally Posted by myrroddin View Post
RegisterUnitEvent looks for unitIDs, which are strings. "player", "target", "boss1", "raid9", etc. What you are passing is a table, which means it probably has a fallback to a valid unitID, or string.
Hi myrroddin,

But the problem persist even if I try these

Lua Code:
  1. object:RegisterUnitEvent("UNIT_AURA", nil, "player");
  2. -- or
  3. object:RegisterUnitEvent("UNIT_AURA", "player", nil);

Originally Posted by Vrul View Post
As long as the table has at least one entry then this should work:
Code:
object:RegisterUnitEvent(event, unpack(unit))
Ah! That's a great tip!

Thank you Vrul
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Why does RegisterUnitEvent responds to all units if the unit parameter is set to nil?


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off