Thread Tools Display Modes
06-10-08, 07:26 PM   #1
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Question OnEvent Help

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_WHISPER")
f:RegisterEvent("CHAT_MSG_CHANNEL")
f:RegisterEvent("VARIABLES_LOADED")
f:SetScript("OnEvent", myMod_OnEvent)

function myMod_OnEvent()
	if (event == "VARIABLES_LOADED") then
		if (not myMod_RANDOM) then
			myMod_RANDOM = {};
		end
		if (not myMod_Enabled) then
			myMod_Enabled = true;
		end
		if (not myMod_RandomReply) then
			myMod_RandomReply = false;
		end
	elseif (event == "CHAT_MSG_CHANNEL") then
		table.insert(myMod_RANDOM, arg1);
		if #(myMod_RANDOM) >= 21 then
			table.remove(myMod_RANDOM, 1);
		end
	end
end
New to frame widgets. For some reason it's not triggering off of "CHAT_MSG_CHANNEL", but works fine for "VARIABLES_LOADED". Even if I removed the variable check, it still won't work.
  Reply With Quote
07-03-08, 07:38 PM   #2
liger
A Kobold Labourer
Join Date: Jun 2008
Posts: 1
Not 100% sure as I'm still new to LUA, but don't you need to declare your table outside your if's if you intend to use it in another event scope? Also init it on an onLoad instead.

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("CHAT_MSG_WHISPER")
f:RegisterEvent("CHAT_MSG_CHANNEL")
f:RegisterEvent("VARIABLES_LOADED")
f:SetScript("OnEvent", myMod_OnEvent)
f:SetScript("OnLoad", myMod_OnLoad)

local myMod_Random

function myMod_OnLoad()
      myMod_Random = {}
end

function myMod_OnEvent()
	if (event == "VARIABLES_LOADED") then
		if (not myMod_Enabled) then
			myMod_Enabled = true;
		end
		if (not myMod_RandomReply) then
			myMod_RandomReply = false;
		end
	elseif (event == "CHAT_MSG_CHANNEL") then
		table.insert(myMod_RANDOM, arg1);
		if #(myMod_RANDOM) >= 21 then
			table.remove(myMod_RANDOM, 1);
		end
	end
end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » 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