View Single Post
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