Thread Tools Display Modes
07-04-07, 01:32 AM   #1
ankoku
A Defias Bandit
Join Date: Jul 2007
Posts: 2
Unable to get RegisterEvent to work correctly

Well I am unable to get my addon to do anything with events...

warcraftlab.toc
Code:
## Interface: 20100
## Author: Ankoku
## Title: |cFF0099FFWarcraftLab |r|cff00aa000.1a|r
## Notes: |cFF0099FFWarcraftLab|r quests/game data collection module.
## OptionalDeps: 
## Dependencies: 
## SavedVariables: _warcraftlabConfig
## SavedVariablesPerCharacter: _warcraftlabQuests _warcraftlabItems
warcraftlab.xml
warcraftlab.xml
Code:
Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
	
	<Script file="warcraftlab.lua"/>

	<Frame name="warcraftlab_MainFrame" hidden="true">
		<Scripts>
      		<OnLoad>
      			WarcraftLab_OnLoad();
      		</OnLoad>
      		<OnEvent>
      			WarcraftLab_OnEvent();
      		</OnEvent>
 		</Scripts>
	</Frame>	
</Ui>
warcraftlab.lua
Code:
--[[ Varibles ]]--
warcraftlab = {};
warcraftlab.version = "0.1a";



--[[ Saved Variable Defaults (Note: All saved vars start with a _) ]]--
_warcraftlabConfig = {};
_warcraftlabConfig.enabled = true;



--[[ SLASH COMMANDS ]]--
SLASH_WARCRAFTLAB1 = "/wl"; 
SLASH_WARCRAFTLAB2 = "/warcraftlab";
SlashCmdList["WARCRAFTLAB"] = function(msg)
	local tag = string.lower(msg);
	
	if(msg == "status") then
		if(_warcraftlabConfig.enabled == true) then
			WarcraftLab_AddChat("Status: |cFF00FF00Enabled", "FFFFFF");
		else
			WarcraftLab_AddChat("Status: |cFFFF0000Disabled", "FFFFFF");
		end
	elseif(msg == "enable") then
		if(_warcraftlabConfig.enabled == true) then
			WarcraftLab_Error("Module is already enabled!");
		else
			_warcraftlabConfig.enabled = true;
			WarcraftLab_AddChat("Module is now [ |cFF00FF00Enabled |cFFFFFFFFF].", "FFFFFF");
		end
	elseif(msg == "disable") then
		if(_warcraftlabConfig.enabled == false) then
			WarcraftLab_Error("Module is already disabled!");
		else
			_warcraftlabConfig.enabled = false;
			WarcraftLab_AddChat("Module is now [ |cFFFF0000Disabled |cFFFFFFFFF].", "FFFFFF");
		end
	
	elseif(msg == "register") then
		WarcraftLab_Register();
	
	else
		WarcraftLab_AddChat("Commands: status, enable, disable.", "FFFFFF");
	end 
end


--[[ TEST FUNCTION: RegisterEvent(WARCRAFTLAB_LOADED) ]]--
function WarcraftLab_Register()
	this:RegisterEvent("WARCRAFTLAB_LOADED");
	WarcraftLab_Debug("RegisterEvent: WARCRAFTLAB_LOADED");
end



--[[ OnLoad Function - Runs when the mod is loaded ]]--
function WarcraftLab_OnLoad()
	this:RegisterEvent("WARCRAFTLAB_LOADED");
	local info = ChatTypeInfo["SYSTEM"];
	WarcraftLab_AddChat("Module Loaded.", "FFFFFF")
end



--[[ AddChat Function - Easily adds dialog to the client's main chat frame ]]--
function WarcraftLab_AddChat(msg, color)
	local info = ChatTypeInfo["SYSTEM"];
	ChatFrame1:AddMessage("|cFF0099FFWarcraftLab|r - |cFF" .. color .. msg, info.r, info.g, info.b, info.id);
	
end

--[[ Debug Function - Easily adds debug information to the client's main chat frame ]]--
function WarcraftLab_Debug(msg)
	local info = ChatTypeInfo["SYSTEM"];
	ChatFrame1:AddMessage("|cFF0099FFWarcraftLab|r - |cFF3C3C3C[DEBUG]:|r |cFFFFFFFF" .. msg, info.r, info.g, info.b, info.id);
end



--[[ Error Function - Easily adds a "plesent" error message to the client's main chat frame ]]--
function WarcraftLab_Error(msg)
	local info = ChatTypeInfo["SYSTEM"];
	ChatFrame1:AddMessage("|cFF0099FFWarcraftLab|r - |cFFFF0000[ERROR]: |r |cFFFFFFFF" .. msg, info.r, info.g, info.b, info.id);
end



--[[ OnEvent Function - This function handles all events ]] --
function WarcraftLab_OnEvent()
	WarcraftLab_Debug("event::" .. event);
	WarcraftLab_Debug("arg1::" .. arg1);
	
	if(event == "WARCRAFTLAB_LOADED") then
		local status;
		if(_warcraftlabConfig.enabled == true) then
			status = "|cFF00FF00Enabled|r";
		else
			status = "|cFFFF0000Disabled|r";
		end
		
		WarcraftLab_AddChat("Data Collection Module is currently [ " .. _warcraftlab_config.enabled .. " |cFFFFFFFF].|r", "FFFFFF");
	end
end
  Reply With Quote
07-04-07, 10:33 AM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Now... I'm not very good at these things, but... It doesn't seem like you're registering for a "real" event. WARCRAFTLAB_LOADED isn't a recognized event in the API, but ADDON_LOADED is.

Anyone with a better knowledge of lua (lots of ya ) can correct me if I'm wrong.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-04-07, 02:28 PM   #3
ankoku
A Defias Bandit
Join Date: Jul 2007
Posts: 2
Yeah that was correct lol, thanks for the help. Now I just need to make sure I check arg1 to make sure it is my addon that has been loaded and not a different one.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Unable to get RegisterEvent to work correctly


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