I have solved this in another way... after looking at Tukui, I just removed all functions. Yes seriously, lol. I can't believe I wasted 3 days on this.
Here is the final file composition, for a very basic options panel, with two toggles that can pass variables from the AceDB into the frame scripts. I think I asked the question in the wrong way, and this doesn't use AceEvent at all, except for the UpdateDisplay function, which I will want later when I add more options to my configuration.
YourName = LibStub("AceAddon-3.0"):NewAddon("YourName", "AceConsole-3.0", "AceEvent-3.0")
local fontFace = "Fonts\\FRIZQT__.TTF"
local fontSize = 11
local defaults = {
profile = {
autosell = true,
autorepair = true,
},
}
local YourName_Options = {
order = 1,
type = "group",
name = "YourName Options",
handler = YourName,
get = function( k ) return YourName.db.profile[k.arg] end,
set = function( k, v ) YourName.db.profile[k.arg] = v; end,
args = {
br01 = {
name = "Enable or Disable Modules",
type = "description",
order = 1,
},
autosell = {
name = "Autosell Grey Items",
type = "toggle",
arg = "autosell",
get = function() return YourName.db.profile.autosell end,
set = function(info, v) YourName.db.profile.autosell = v
end,
order = 2,
},
autorepair = {
name = "Auto Repair",
type = "toggle",
arg = "autorepair",
get = function() return YourName.db.profile.autorepair end,
set = function(info, v) YourName.db.profile.autorepair = v
end,
order = 3,
},
},
}
function YourName:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("YourNameDB", defaults, "Default")
self.db.RegisterCallback(self, "OnProfileChanged", "UpdateDisplay")
self.db.RegisterCallback(self, "OnProfileCopied", "UpdateDisplay")
self.db.RegisterCallback(self, "OnProfileReset", "UpdateDisplay")
LibStub("AceConfig-3.0"):RegisterOptionsTable("XZZTOP", YourName_Options)
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("XZZTOP", "Your Title")
end
function YourName:OnEnable()
--
end
function YourName:UpdateDisplay()
--
end
local goldframe = CreateFrame("Frame", "goldframe", UIParent)
goldframe:ClearAllPoints()
goldframe:SetPoint("CENTER", UIParent, "CENTER", 0,0)
goldframe:SetFrameStrata("BACKGROUND")
goldframe:SetHeight(24)
goldframe:SetWidth(200)
local goldtext = goldframe:CreateFontString("mygold", "Overlay")
goldtext:SetPoint("CENTER", goldframe, "CENTER", 0, 0)
goldtext:SetFont(fontFace, fontSize)
goldtext:SetText( "I AM TEXT" )
goldframe:SetScript("OnMouseUp", function(self, btn)
if btn == "RightButton" then
print ("rightbutton")
elseif btn == "MiddleButton" then
print ("middlebutton")
else
if YourName.db.profile.autosell then
print ("autosell is true")
else
print ("autosell is false")
end
end
end)
local q = CreateFrame("Frame")
q:SetScript("OnEvent", function()
if YourName.db.profile.autosell then
local c = 0
for b=0,4 do
for s=1,GetContainerNumSlots(b) do
local l = GetContainerItemLink(b, s)
if l then
local p = select(11, GetItemInfo(l))*select(2, GetContainerItemInfo(b, s))
if select(3, GetItemInfo(l))==0 then
UseContainerItem(b, s)
PickupMerchantItem()
c = c+p
end
end
end
end
if c>0 then
local g, s, c = math.floor(c/10000) or 0, math.floor((c%10000)/100) or 0, c%100
end
end
if not IsShiftKeyDown() then
if CanMerchantRepair() and YourName.db.profile.autosell then
cost, possible = GetRepairAllCost()
if cost>0 then
if possible then
RepairAllItems()
local c = cost%100
local s = math.floor((cost%10000)/100)
local g = math.floor(cost/10000)
else
--
end
end
end
end
end)
q:RegisterEvent("MERCHANT_SHOW")
Thanks everyone for all your advice, once again! :)
AceEvent RegisterEvent and Frame RegisterEvent aren't the same thing, at all. AceEvent RegisterEvent internally uses Frame one but that's none of your business. Both have different way of working and expect different arguments.
Moreover, SetScript is used to define script handlers for frames. Events are one type of script handler. There is no equivalent for SetScript in AceEvent because it doesn't make sense for any other thing than events.
-- Using a frame example
local frame = CreateFrame("Frame")
local function SomeOtherHandler(event)
-- Do other things
end
-- frame:SetScript expects a string (the script name) and a function (the handler)
frame:SetScript('OnEvent', function(self, event)
-- Note: here, self == frame
if event == "THIS_EVENT" then
-- do this
elseif event == "THAT_EVENT" or event == "OTHER_EVENT"
-- do that
elseif event == "FOURTH_EVENT" then
SomeOtherHandler(event)
end
end)
local function Frame_OnEnter(self)
-- Note: here, self == frame
-- Do something
end
frame:SetScript('OnEnter', Frame_OnEnter) -- No method name there, only functions
-- All these events will be handled by the OnEvent script you defined above
frame:RegisterEvent("THIS_EVENT")
frame:RegisterEvent("THAT_EVENT")
frame:RegisterEvent("OTHER_EVENT")
frame:RegisterEvent("FOURTH_EVENT")
Same thing using AceAddon and AceEvent :
MyAddon = LibStub('AceAddon-3.0'):NewAddon('MyAddon', 'AceEvent-3.0')
local function SomeOtherHandler(event)
-- Do other things, no self there
end
local frame = CreateFrame("Frame")
local function Frame_OnEnter(self)
-- Note: here, self == frame
-- To act on MyAddon, you could do something like this:
MyAddon:OnEnterFrame()
end
frame:SetScript('OnEnter', Frame_OnEnter)
function MyAddon:OnEnable()
-- Have THIS_EVENT handled by the method "THIS_EVENT" of self (aka MyAddon)
self:RegisterEvent('THIS_EVENT')
-- Have THAT_EVENT handled by the method "THAT_EVENT"
self:RegisterEvent('THAT_EVENT')
-- Have OTHER_EVENT handled by the method "THAT_EVENT"
self:RegisterEvent('OTHER_EVENT', 'THAT_EVENT')
')
-- Have FOURTH_EVENT handled by the function SomeOtherHandler
self:RegisterEvent('FOURTH_EVENT', SomeOtherHandler)
end
function MyAddon:THIS_EVENT(event)
-- Note: here, self == MyAddon
end
function MyAddon:THAT_EVENT(event)
-- Note: here, self == MyAddon
end
function MyAddon:OnEnterFrame()
-- Note: here, self == MyAddon
end
as a new author, be careful with libraries. many libs mimic blizzard api functions and sometimes it's not clear what is actually going on. in this case, i think you're confusing ace event handling with blizzard event handling. ace uses similar syntax and without knowing the nature of the objects you're using, RegisterEvent() could be two wholly different things.
or as a function (Gold)
I'm not home to test or look at other addon code easily.
Here is the final file composition, for a very basic options panel, with two toggles that can pass variables from the AceDB into the frame scripts. I think I asked the question in the wrong way, and this doesn't use AceEvent at all, except for the UpdateDisplay function, which I will want later when I add more options to my configuration.
Thanks everyone for all your advice, once again! :)
AceEvent RegisterEvent and Frame RegisterEvent aren't the same thing, at all. AceEvent RegisterEvent internally uses Frame one but that's none of your business. Both have different way of working and expect different arguments.
Moreover, SetScript is used to define script handlers for frames. Events are one type of script handler. There is no equivalent for SetScript in AceEvent because it doesn't make sense for any other thing than events.
Same thing using AceAddon and AceEvent :
AceEvent handles either; strings are treated as names of member functions in your addon's table, function pointers are called directly.