WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   my addon does nothing (https://www.wowinterface.com/forums/showthread.php?t=34442)

SignOfDoom 08-12-10 09:34 AM

my addon does nothing
 
hi
at first i have to say that this is the first addon i create do dnt expect to much.

i have this code
Code:

frame = CreateFrame("Frame")
frame:RegisterEvent("CHAT_MSG_LOOT")

function frame:OnEvent(event, ...)
        if event == "CHAT_MSG_LOOT" then
                print("juhu")
        end
end

frame:SetScript("OnEvent", frame.OnEvent)

in my addon but ingame nothing happens. can anybody say me what i am doing wrong?

xConStruct 08-12-10 09:49 AM

Code looks correct to me. Could you please post your .toc-file?

yj589794 08-12-10 09:54 AM

you should make frame local
Code:

local frame = CreateFrame("Frame")
It won't make your addon run, but it will stop you injecting a commonly named item into the global namespace.

cloudwolf 08-12-10 10:39 AM

frame:Onevent is different than frame.onevent. your not calling your function. Also please use less generic names. Also PLEASE localize your variables. By having a global like that floating in name space you could break more than just your own addon.

SignOfDoom 08-12-10 11:31 AM

i changed my code to that:
Code:

local tracker = CreateFrame("Frame")
tracker:RegisterEvent("CHAT_MSG_LOOT")

local function Looten(event, ...)
        if event == "CHAT_MSG_LOOT" then
                print("it works")
        end
end

tracker:SetScript("OnEvent", Looten)

but still nothing happens

dr_AllCOM3 08-12-10 11:36 AM

Try ChatFrame1:AddMessage() instead of print().

xConStruct 08-12-10 11:37 AM

print() should do fine normally.

But this time you need to explicitly add "self" to the function, because you removed the "frame:" (which acts as 'self').

Code:

local tracker = CreateFrame("Frame")
tracker:RegisterEvent("CHAT_MSG_LOOT")

local function Looten(self, event, ...)
        if event == "CHAT_MSG_LOOT" then
                print("it works")
        end
end

tracker:SetScript("OnEvent", Looten)

Still, if it doesn't work, please post your .toc-file! Or add a print("test") to the top of your file to see if it gets loaded at all.

SignOfDoom 08-12-10 11:44 AM

im so stupid -.-
it works now. it was the toc file ^^
thank you very much


All times are GMT -6. The time now is 01:46 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI