Originally Posted by Xrystal
In this example the keys are health and name and the values are the values after the '=' in otherwords the table of events and whether they are unitSpecific ( true/false). As far as I am aware these could be written as :
displayEvents[health][UNIT_HEALTH] = true
displayEvents["health"]["UNIT_HEALTH"] = true
displayEvents.health["UNIT_HEALTH"] = true
displayEvents.health.unit_health = true
|
Lines 2 and 3 do the same thing as each other, but lines 1 and 4 are both different.
Line 1 is using the values of the variables
health and
UNIT_HEALTH as keys instead of the strings
health and
UNIT_HEALTH like line 2 and 3.
Line 4 is using the string
unit_health as a key instead of
UNIT_HEALTH. Lua is case-sensitive, so these are two completely separate keys. If it was in uppercase, it would be the same as lines 2 and 3.
Originally Posted by Jonisaurus
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!
|
The OnEvent handler always receives two arguments:
self (the frame that the event fired for) and
event (the event that fired). After these two, it receives any arguments passed by the event itself. All of the UNIT_X events have
unit (the unitID that the event fired for) as their first argument.