Thread Tools Display Modes
03-19-09, 07:39 PM   #1
Seyss
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 10
OnEvent help

Hi all,

I'm catching the event COMBAT_LOG_EVENT_UNFILTERED by doing this:

On UI.xml:
<OnEvent>
UI_OnEvent(event,arg1,arg2,arg3,arg4,arg5,arg6,...)
</OnEvent>

On UI.lua:
function UI_OnEvent(event,arg1,arg2...)
if (event == "COMBAT_LOG_EVENT_UNFILTERED") then
......

But I think this way is too slow. It checks ALL WOW EVENTS for the event I want to catch.

Is there a way to call a function when ONLY this event is generated in the game?

Thanks very much !!
  Reply With Quote
03-21-09, 12:08 AM   #2
Korlong
A Defias Bandit
Join Date: Mar 2009
Posts: 2
Standard practice is to create a table of events you actually want to listen to, as looking up a handler in a table of events is way faster (and syntactically nicer) than grinding through a massive cascading if statement.

I think it's easier for me to just paste some code:

Code:
Events = {
				UNIT_RAGE = function(fm) fm:OnStatsChanged() end,
				UNIT_AURA = function(fm) fm:OnStatsChanged() end,
				UNIT_STATS = function(fm) fm:OnStatsChanged() end,
				PLAYER_AURAS_CHANGED = function(fm) fm:OnStatsChanged() end,
				UNIT_INVENTORY_CHANGED = function(fm) fm:OnEquipmentChanged(); fm:OnStatsChanged(); end,
				PLAYER_LEVEL_UP = function(fm) fm:OnStatsChanged() end,
				UNIT_SPELLCAST_SUCCEEDED = function(fm) fm:OnSpellCast() end,
				CHARACTER_POINTS_CHANGED = function(fm) fm:OnTalentsChanged() end,
				UPDATE_SHAPESHIFT_FORM = function(fm) fm:OnStatsChanged() end,
				PLAYER_REGEN_DISABLED = function(fm) fm:OnEnterCombat() end,
				PLAYER_REGEN_ENABLED = function(fm) fm:OnLeaveCombat() end
			}
Code:
	self:GetFrame():SetScript(
		"OnEvent",
		function(frame, event)
			FuryMonitor.Main:GetInstance().Events[event](FuryMonitor.Main:GetInstance());
		end
	);
All of the event arguments are global variables, and WoW's addons run in a single threaded environment, so you don't need to pass them to your event handler:
Code:
function FuryMonitor.Main:OnSpellCast()
	local unitName = arg1;
	if unitName ~= "player" then
		return;
	end	

	self:SetRotationStabilized(false);
	local spellName = arg2;
	local ability = self:GetAbilityByName(arg2);
	if ability then
		FuryMonitor.Util.UpdateTime();
		ability:Used();
	end
end
Edit: see, look, this is even useful for me! It helps me find really dumb code!

Last edited by Korlong : 03-21-09 at 12:12 AM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » OnEvent help


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off