View Single Post
11-11-12, 04:04 PM   #14
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Sorry, could I ask one other question about the examples you provided earlier regarding the processing of modules?

See if I were to define this function (copy/pasted from your examples below):

Lua Code:
  1. function addon:ADDON_LOADED(name)
  2.      if name ~= addonName then return end
  3.      -- By the time this event fires for this addon, all of
  4.      -- this addon's files and saved variables have loaded.
  5.  
  6.      -- Initialize your saved variables here.
  7.  
  8.      -- Do core initialization stuff here.
  9.  
  10.      for moduleName, moduleObject in pairs(self.modules) do
  11.           if self.db.modules[moduleName].enable then
  12.                moduleObject:Enable()
  13.           end
  14.      end
  15. end

I'm sorry if this is a stupid question, but in this example where the function is called "ADDON_LOADED", I take it I am still required to create a handler frame and register to the event "ADDON_LOADED" and include a line like:

Lua Code:
  1. eventHandler:SetScript("OnEvent", function(self, event, arg1, arg2, arg3, arg4)
  2.     if (event == "ADDON_LOADED") then    -- does this line even need to be here?
  3.         addonName:ADDON_LOADED(arg1);
  4.     end
  5. end);


The reason I ask is because I've never actually defined a function using an event as it's name before. I've always just created a handler frame, given it an OnEvent handler and called each function that I want it to call when a particular event fires.

I'm just wanting to rule out that simply defining the function is enough... ie because of the way in which it has been defined, would it automatically be called when the event fires rendering the above SetScript pointless?

Thanks again. I hope I've been able to make the question clear enough.


Aanson.
__________________
__________________
  Reply With Quote