Thread Tools Display Modes
04-12-08, 11:19 PM   #1
Pixlin
A Defias Bandit
Join Date: Apr 2008
Posts: 2
Registering LOOT_OPENED event doesn't work for me

I'm trying to figure out how to trigger a piece of code to occur whenever a loot bag is opened... I wrote a "hello world" wrapper to test my trigger with and can't get it to fire. Does anyone know what's wrong with what I have?

addon.toc
Code:
## Interface: 20400

## Title: Test

## Notes: none

## Dependencies:

addon.lua
addon.lua:
Code:
function myBla(self, event, ...)
  DEFAULT_CHAT_FRAME:AddMessage("YOOHOO", 0.0, 1.0, 0.0);
end

local f = CreateFrame("Frame", "MyAddOnFrame", nil);
f:SetScript("OnEvent", myBla);
f:RegisterEvent("LOOT_OPENED");
f:RegisterEvent("OPEN_MASTER_LOOT_LIST");
  Reply With Quote
04-13-08, 03:54 AM   #2
Inokis
EQInterface Staff
 
Inokis's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 156
Code:
function somename_OnLoad()
	this:RegisterEvent("LOOT_OPENED");
end

function somename_OnEvent()
		if (event == "LOOT_OPENED") then
			arbitrary scripting
		end
end

Then you call the functions through the .xml

Code:
<Scripts>
	<OnLoad>
		somename_OnLoad();
	</OnLoad>
	<OnEvent>
		somename_OnEvent(event);
	</OnEvent>

</Scripts>
__________________
If not yourself, who can you count on...
  Reply With Quote
04-13-08, 07:05 AM   #3
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Pixlin's code looks fine (appart from the global event function). The only thing I can think of is WoW might not like having an empty dependences field.

Maybe put
Code:
DEFAULT_CHAT_FRAME:AddMessage("TestLoaded", 0.0, 1.0, 0.0);
after
Code:
local f = CreateFrame("Frame", "MyAddOnFrame", nil);
  Reply With Quote
04-13-08, 06:47 PM   #4
Pixlin
A Defias Bandit
Join Date: Apr 2008
Posts: 2
Figured it out late last night actually... my code was fine, but apparently the order of my statements was wrong:

old (bad):
Code:
local f = CreateFrame("Frame", "MyAddOnFrame", nil);
f:SetScript("OnEvent", myBla);
f:RegisterEvent("LOOT_OPENED");
f:RegisterEvent("OPEN_MASTER_LOOT_LIST");
new (good):
Code:
local f = CreateFrame("Frame", "MyAddOnFrame", nil);
f:RegisterEvent("LOOT_OPENED");
f:RegisterEvent("OPEN_MASTER_LOOT_LIST");
f:SetScript("OnEvent", myBla);

Of course, now that I got that working, I'm realizing that its not what I need.... I am trying to muck with my inventory dynamically and my code isn't recognizing the changes to my bags.

I think I'm going to have to use coroutines *shudder*..... Questions will soon be posted, since my attempts so far have been going down in flames
  Reply With Quote
04-14-08, 05:53 AM   #5
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Originally Posted by Pixlin View Post
Figured it out late last night actually... my code was fine, but apparently the order of my statements was wrong:

old (bad):
Code:
local f = CreateFrame("Frame", "MyAddOnFrame", nil);
f:SetScript("OnEvent", myBla);
f:RegisterEvent("LOOT_OPENED");
f:RegisterEvent("OPEN_MASTER_LOOT_LIST");
new (good):
Code:
local f = CreateFrame("Frame", "MyAddOnFrame", nil);
f:RegisterEvent("LOOT_OPENED");
f:RegisterEvent("OPEN_MASTER_LOOT_LIST");
f:SetScript("OnEvent", myBla);

Of course, now that I got that working, I'm realizing that its not what I need.... I am trying to muck with my inventory dynamically and my code isn't recognizing the changes to my bags.

I think I'm going to have to use coroutines *shudder*..... Questions will soon be posted, since my attempts so far have been going down in flames
Yeh I'm having a similar problem, me thinks I may have to use a OnUpdate to add a delay
  Reply With Quote
04-14-08, 09:44 AM   #6
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
That's interesting. I wonder if WoW clears the OnEvent script if no events are registered automatically.

EDIT: P.S. Look for BAG_UPDATE

EDIT2: Inokis, that code is bad. Very bad. Don't use the "this" variable. Instead, use "self" because it is a local. Your OnEvent script also doesn't take the variable that you passed it. The function header should be "somename_OnEvent(event)" otherwise you will use the global event which is, again, bad.
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/

Last edited by Shirik : 04-14-08 at 09:50 AM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Registering LOOT_OPENED event doesn't work for me


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