-
Posted by Myrroddin on Mon, 27 Oct 2008 08:58:21
MyrroTip = AceLibrary("AceAddon-3.0"):new("AceConsole-3.0", "AceEvent-3.0", "AceLocale-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("MyrroTip", true)
MyrroTip_Options {}
function MyrroTip:OnInitialize()
-- Called when the addon is loaded
self:RegisterEvent("PLAYER_LOGIN")
if event == "PLAYER_LOGIN" then
MessageFrame:AddMessage (L("Type /myrrotip or /myrrt for options"))
end
-- create slash commands
SLASH_MESSAGE1 = "/myrrotip";
SLASH_MESSAGE2 = "/myrrt";
SlashCmdList ["MYRROTIP" = function(text)
if InCombatLockdown() then
MessageFrame:AddMessage (L("You cannot configure MyrroTip during while in combat."))
return
end
-- process slash commands
if text == "" then
-- check addons to make sure MyrroTip_Options is installed and enabled
for i = 1, GetNumAddons() do
local name, _, notes, enabled, loadable = GetAddOnInfo(i)
if IsAddOnLoadOnDemand(i) and enabled and loadable and not IsAddOnLoaded(i) then
for _,dep in ipairs(tmp(GetAddOnDependencies(name))) do
if dep == "MyrroTip" then
loaded, reason = LoadAddon ("MyrroTip_Options")
-- check for loading errors
if loaded ~= 1 then
MessageFrame:AddMessage (L("MyrroTip_Options not loaded because: " .. reason))
MessageFrame:AddMessage (L("You cannot configure MyrroTip."))
return
end
end
end
end
elseif text ~= "" then
-- check addons to make sure MyrroTip_Options is installed and enabled
for i = 1, GetNumAddons() do
local name, _, notes, enabled, loadable = GetAddOnInfo(i)
if IsAddOnLoadOnDemand(i) and enabled and loadable and not IsAddOnLoaded(i) then
for _,dep in ipairs(tmp(GetAddOnDependencies(name))) do
if dep == "MyrroTip" then
loaded, reason = LoadAddon ("MyrroTip_Options")
-- check for loading errors
if loaded ~= 1 then
MessageFrame:AddMessage (L("MyrroTip_Options not loaded because: " .. reason))
MessageFrame:AddMessage (L("You cannot configure MyrroTip."))
return
end
end
end
end
end
end
function MyrroTip:OnEnable()
-- Called when the addon is enabled
CreateFrame("GameToolTip", "MyrroTip", UIParent, "GameToolTipTemplate")
GameToolTip_SetDefaultAnchor(MyrroTip, UIParent)
end
function MyrroTip:OnDisable()
-- Called when the addon is disabled
endI realize the dependancy MyrroTip_Options hasn't been created yet, but this addon should at least work up to a point, yet when I enter the slash commands, I get not found errors. Also, is there a place to link files so I don't have a ridiculously long post?
-
Posted by Myrroddin on Mon, 27 Oct 2008 08:58:21
MyrroTip = AceLibrary("AceAddon-3.0"):new("AceConsole-3.0", "AceEvent-3.0", "AceLocale-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("MyrroTip", true)
MyrroTip_Options {}
function MyrroTip:OnInitialize()
-- Called when the addon is loaded
self:RegisterEvent("PLAYER_LOGIN")
if event == "PLAYER_LOGIN" then
MessageFrame:AddMessage (L("Type /myrrotip or /myrrt for options"))
end
-- create slash commands
SLASH_MESSAGE1 = "/myrrotip";
SLASH_MESSAGE2 = "/myrrt";
SlashCmdList ["MYRROTIP" = function(text)
if InCombatLockdown() then
MessageFrame:AddMessage (L("You cannot configure MyrroTip during while in combat."))
return
end
-- process slash commands
if text == "" then
-- check addons to make sure MyrroTip_Options is installed and enabled
for i = 1, GetNumAddons() do
local name, _, notes, enabled, loadable = GetAddOnInfo(i)
if IsAddOnLoadOnDemand(i) and enabled and loadable and not IsAddOnLoaded(i) then
for _,dep in ipairs(tmp(GetAddOnDependencies(name))) do
if dep == "MyrroTip" then
loaded, reason = LoadAddon ("MyrroTip_Options")
-- check for loading errors
if loaded ~= 1 then
MessageFrame:AddMessage (L("MyrroTip_Options not loaded because: " .. reason))
MessageFrame:AddMessage (L("You cannot configure MyrroTip."))
return
end
end
end
end
elseif text ~= "" then
-- check addons to make sure MyrroTip_Options is installed and enabled
for i = 1, GetNumAddons() do
local name, _, notes, enabled, loadable = GetAddOnInfo(i)
if IsAddOnLoadOnDemand(i) and enabled and loadable and not IsAddOnLoaded(i) then
for _,dep in ipairs(tmp(GetAddOnDependencies(name))) do
if dep == "MyrroTip" then
loaded, reason = LoadAddon ("MyrroTip_Options")
-- check for loading errors
if loaded ~= 1 then
MessageFrame:AddMessage (L("MyrroTip_Options not loaded because: " .. reason))
MessageFrame:AddMessage (L("You cannot configure MyrroTip."))
return
end
end
end
end
end
end
function MyrroTip:OnEnable()
-- Called when the addon is enabled
CreateFrame("GameToolTip", "MyrroTip", UIParent, "GameToolTipTemplate")
GameToolTip_SetDefaultAnchor(MyrroTip, UIParent)
end
function MyrroTip:OnDisable()
-- Called when the addon is disabled
endI realize the dependancy MyrroTip_Options hasn't been created yet, but this addon should at least work up to a point, yet when I enter the slash commands, I get not found errors. Also, is there a place to link files so I don't have a ridiculously long post?
-
Posted by jnwhiteh on Tue, 28 Oct 2008 05:23:41
You can post them as http://pastey.net and then link them here. There are a few things that don't make sense here, in particular your slash command registration:
You want to create two globals here like so:
SLASH_MYRROTIP1 = "/myrrotip"
SLASH_MYRROTIP2 = "/myrrt"Then you register the slash command handler using the same "tag", i.e.
SlashCmdList["MYRROTIP"] = function(text) ChatFrame1:AddMessage(tostring(text)) end
This simple slash command will echo whatever you type after the slash command to the chat window.
-
Posted by Myrroddin on Thu, 30 Oct 2008 18:07:00
Thank you so much! Not only did you point out my (rather obvious - /facepalm) error, you inspired me to fix other things in this code.
Many thank yous :-)