View Single Post
01-25-14, 07:52 PM   #5
Jonisaurus
An Aku'mai Servant
 
Jonisaurus's Avatar
Join Date: Aug 2011
Posts: 35
Reading alternative code like that really helps. I have a few questions:

1. The pairs() function. I don't quite understand it.
Earlier you declare 'events' to be the result of the 'displayEvents[displayType]' table access.
Where does 'unitSpecific' come from and what do 'event' and 'unitSpecific' do exactly in 'events'?
Code:
for event, unitSpecific in pairs(events) do
			if unitSpecific then
				f:RegisterUnitEvent(event, unit)
			else
				f:RegisterEvent(event)
			end
		end
2. Why did you set the value of the event keys to a BOOLEAN value? And why is it UNIT_HEALTH and not "UNIT_HEALTH"?
Code:
local displayEvents = {
		health = {
			UNIT_HEALTH = true,
			UNIT_MAXHEALTH = true,
		},
		name = {
			PLAYER_TARGET_CHANGED = false,
			UNIT_NAME_UPDATE = true,
		},
	}
3. What exactly does this expression mean? Why is the existence of 'hp' queried twice?
Code:
SetText(hp and hp > 0 and hp or nil)
4. In order for 'self.unit' to work the 'frame:SetScript("OnEvent", handler)' function passes the 'frame' as first parameter 'self' to the handler function, correct?
How would the handler function ever receive the third parameter 'unit' directly though? When would '(unit or self.unit)' ever resort to using 'unit'?
Code:
health = function(self, event, unit)
			local hp = UnitHealth(unit or self.unit)
			self:SetText(hp and hp > 0 and hp or nil)
		end,
Thanks!
  Reply With Quote