View Single Post
12-29-12, 05:10 AM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Your question is a bit unclear, but yes, you can have multiple event handlers defined in the same file.

If you want to set different event handler scripts on different frames, just define two functions. Function names are just variables, so they follow all the same rules as other variables; in particular, giving a variable a name that's already assigned to another variable overwrites the first variable, so you would want to give your functions unique names. Example:

Code:
local function RepBar_OnEvent(self, event, ...)
	...		
end

for i, v in ipairs(repTable) do
	...
	currframe:SetScript("OnEvent", RepBar_OnEvent)
	currframe:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
	...
end

local function SomeOtherFrame_OnEvent(self, event, ...)
	...
end

otherframe:SetScript("OnEvent", SomeOtherFrame_OnEvent)
otherframe:RegisterEvent("SOME_EVENT")
otherframe:RegisterEvent("SOME_OTHER_EVENT")
If you want a single function on a single frame to process different events differently, you'd do something like this:

Code:
local function RepBar_OnEvent(self, event, ...)
	if event == "CURRENCY_DISPLAY_UPDATE" then
		-- do something
	else
		-- assume it's the other event, and do something else
	end
end

for i, v in ipairs(repTable) do
	...
	currframe:SetScript("OnEvent", RepBar_OnEvent)
	currframe:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
	currframe:RegisterEvent("SOME_OTHER_EVENT")
	...
end
You could, of course, handle more than two events in more than two ways, by adding to the if/else logic.

If you're trying to add a bar that displays honor (or any other currency) I'd suggest Method #1, and creating that bar separately (ie. not in your existing ipairs loop through repTable), since you don't need a currency bar to respond to rep events, or vice versa.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote