So about 2 years ago I wrote an addon to just play audio events based on reading the combat log. I am getting errors and just have some basic questions if this is how it would be. Here is the opening to my addon that just scans the combat log for events.
Is any of that wrong or has changed, the addon used to work back in BC but now it gets errors including line 1 attempt to call global helloworld (a nil value)
Ty for all the help.
here is a few lines of code from the addon...
if arg1 == 31224 then
if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 or dstFlags == 0x548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\cloak.mp3");
end
if you're getting a nil HelloWorld() error, then it sounds to me like the problem is syntax or maybe in the way the thing is loaded. it's possible that the loading mechanisms have changed since then. what is your first error? that's really the only one that matters.
i know you're just trying to get a quick question in, but it's probably best to post your entire code.
if you're getting a nil HelloWorld() error, then it sounds to me like the problem is syntax or maybe in the way the thing is loaded. it's possible that the loading mechanisms have changed since then. what is your first error? that's really the only one that matters.
i know you're just trying to get a quick question in, but it's probably best to post your entire code.
Sorry sorry here is the code below. While I wrote all the if/else code and figured out how to understand the combat events, I did not write the opening code as I didn't understand how to get it started. A very nice guy on a forum helped me with that to get it all started.
I would love if someone could do that here just the opening code to declare the addon and such, I would LOVE it actually :)
here is the code:
function HelloWorld()
this:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
this:SetScript("OnEvent", function(self, event, ...)
local timestamp, eventType, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags = select(1, ...)
local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11 = select(9, ...)
if eventType == "SPELL_AURA_REMOVED" then
--if arg1 == 28189 then
-- if dstFlags == 0x511 then
--PlaySoundFile("Interface\\AddOns\\MySounds\\felremoved.mp3");
-- end
--elseif arg1 == 6215 then
-- if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 or dstFlags==0x548 then
--PlaySoundFile("Interface\\AddOns\\MySounds\\fearremoved.mp3");
-- end
--end
elseif eventType == "SPELL_CAST_SUCCESS" then
if arg1 == 8143 then
if srcFlags ==0x30548 or srcFlags==0x10548 or srcFlags==0x20548 or srcFlags==0x548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\tremor.mp3");
end
--elseif arg1 == 18425 then
-- if srcFlags ==0x30548 or srcFlags==0x10548 or srcFlags==0x20548 or srcFlags==0x548 then
-- PlaySoundFile("Interface\\AddOns\\MySounds\\kick.mp3");
-- end
elseif arg1 == 6554 then
if srcFlags ==0x30548 or srcFlags==0x10548 or srcFlags==0x20548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\pummel.mp3");
end
elseif arg1 == 38768 then
if srcFlags ==0x30548 or srcFlags==0x10548 or srcFlags==0x20548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\kick.mp3");
end
end
elseif eventType=="SPELL_AURA_APPLIED" then
if dstGUID == 0x21A4E0F then
--DEFAULT_CHAT_FRAME:AddMessage(dstGUID);
end
if dstName == "Benga" then
if arg1 == 34936 then
PlaySoundFile("Interface\\AddOns\\MySounds\\backlash.mp3");
elseif arg1 == 30456 then
DEFAULT_CHAT_FRAME:AddMessage("NIGH!");
PlaySoundFile("Interface\\AddOns\\MySounds\\nigh.mp3")
elseif arg1 == 30300 then
PlaySoundFile("Interface\\AddOns\\MySounds\\nether.mp3");
elseif arg1 == 27828 then
PlaySoundFile("Interface\\AddOns\\MySounds\\focusedcasting.mp3");
elseif arg1 == 37310 then
PlaySoundFile("Interface\\AddOns\\MySounds\\bloodlust.mp3");
elseif arg1 == 30457 then
PlaySoundFile("Interface\\AddOns\\MySounds\\vulnerability.mp3");
elseif arg1 == 28189 then
PlaySoundFile("Interface\\AddOns\\MySounds\\felremoved.mp3");
elseif arg1 == 1044 then
PlaySoundFile("Interface\\AddOns\\MySounds\\freedom.mp3");
elseif arg1 == 10278 then
PlaySoundFile("Interface\\AddOns\\MySounds\\protection.mp3");
elseif arg1 == 10060 then
PlaySoundFile("Interface\\AddOns\\MySounds\\powerinfusion.mp3");
elseif arg1 == 33206 then
PlaySoundFile("Interface\\AddOns\\MySounds\\painsuppression.mp3");
elseif arg1 == 33786 then
PlaySoundFile("Interface\\AddOns\\MySounds\\cyclone.mp3");
elseif arg1 == 18803 then
PlaySoundFile("Interface\\AddOns\\MySounds\\focus.mp3");
elseif arg1 == 19503 then
PlaySoundFile("Interface\\AddOns\\MySounds\\scattershot.mp3");
elseif arg1 == 20066 then
PlaySoundFile("Interface\\AddOns\\MySounds\\repentance.mp3");
elseif arg1 == 11297 then
PlaySoundFile("Interface\\AddOns\\MySounds\\sap.mp3");
elseif arg1 == 1833 then
PlaySoundFile("Interface\\AddOns\\MySounds\\cheapshot.mp3");
elseif arg1 == 8643 then
PlaySoundFile("Interface\\AddOns\\MySounds\\kidneyshot.mp3");
elseif arg1 == 38764 then
PlaySoundFile("Interface\\AddOns\\MySounds\\gouge.mp3");
elseif arg1 == 2825 then
PlaySoundFile("Interface\\AddOns\\MySounds\\bloodlust.mp3");
elseif arg1 == 18469 then
PlaySoundFile("Interface\\AddOns\\MySounds\\counterspell.mp3");
end
end
if arg1 == 31224 then
if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 or dstFlags == 0x548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\cloak.mp3");
end
elseif arg1 == 34471 then
if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 or dstFlags == 0x548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\beastialwrath.mp3");
end
elseif arg1 == 36554 then
if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\Shadowstep.mp3");
end
elseif arg1 == 1020 then
if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 or dstFlags == 0x548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\bubble.mp3");
end
elseif arg1 == 26888 then
if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\vanish.mp3");
end
elseif arg1 == 23920 then
if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\spellreflect.mp3");
end
elseif arg1 == 45438 then
if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 or dstFlags==0x548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\iceblock.mp3");
end
elseif arg1 == 27223 then
if dstFlags == 0x30548 or dstFlags==0x10548 or dstFlags==0x20548 or dstFlags==0x548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\deathcoil.mp3");
end
elseif arg1 == 24259 then
if dstFlags == 0x30548 or dstFlags==0x10548 or dstFlags==0x20548 or dstFlags==0x548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\spelllock.mp3");
end
end
elseif eventType=="PARTY_KILL" then
if srcName == "Benga" then
PlaySoundFile("Interface\\AddOns\\MySounds\\dominating.mp3");
end
elseif eventType == "SPELL_DISPEL" then
--if arg1 == 2782 then
-- if srcFlags ==0x30548 or srcFlags==0x10548 or srcFlags==0x20548 or srcFlags==0x548 then
-- if arg5 == "Curse of Weakness" then
-- PlaySoundFile("Interface\\AddOns\\MySounds\\weaknessremoved.mp3");
-- elseif arg5 == "Curse of Tongues" then
-- PlaySoundFile("Interface\\AddOns\\MySounds\\tonguesremoved.mp3");
-- elseif arg5 == "Curse of Agony" then
-- PlaySoundFile("Interface\\AddOns\\MySounds\\cleanse.mp3");
-- end
-- end
elseif arg1 == 4987 then
if srcFlags ==0x30548 or srcFlags==0x10548 or srcFlags==0x20548 or srcFlags==0x548 then
if arg4 == 27216 or arg4 == 30911 or arg4 == 25222 or arg4 == 25218 or arg4 == 33110 or arg4 == 25368 then
DEFAULT_CHAT_FRAME:AddMessage("cleanse");
PlaySoundFile("Interface\\AddOns\\MySounds\\cleanse.mp3");
end
if arg4 == 30108 then
DEFAULT_CHAT_FRAME:AddMessage("ua hit");
PlaySoundFile("Interface\\AddOns\\MySounds\\uahit.mp3");
end
end
elseif arg1 == 988 then
if srcFlags ==0x30548 or srcFlags==0x10548 or srcFlags==0x20548 or srcFlags==0x548 then
if arg4 == 27216 or arg4 == 30911 or arg4 == 25222 or arg4 == 25218 or arg4 == 33110 or arg4 == 25368 then
DEFAULT_CHAT_FRAME:AddMessage("dispel!");
PlaySoundFile("Interface\\AddOns\\MySounds\\dispel.mp3");
end
if arg4 == 30108 then
DEFAULT_CHAT_FRAME:AddMessage("ua hit");
PlaySoundFile("Interface\\AddOns\\MySounds\\uahit.mp3");
end
end
elseif arg1 == 32375 and arg4 == 1020 then
if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 or dstFlags==0x548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\bubbledispelled.mp3");
end
end
elseif eventType == "SPELL_MISSED" then
if srcName == "Benga" then
if arg4 == "IMMUNE" then
PlaySoundFile("Interface\\AddOns\\MySounds\\immune.mp3");
elseif arg4 == "RESIST" then
PlaySoundFile("Interface\\AddOns\\MySounds\\resist.mp3");
end
elseif srcName == "Jhaajhom" then
if arg1 == 19647 then
PlaySoundFile("Interface\\AddOns\\MySounds\\spelllockresist.mp3");
end
end
elseif eventType=="SWING_DAMAGE" then
if dstName == "Jhaajhom" then
if srcName == "Tremor Totem" then
PlaySoundFile("Interface\\AddOns\\MySounds\\tremordown.mp3");
end
end
end
end)
end
if you're getting a nil HelloWorld() error, then it sounds to me like the problem is syntax or maybe in the way the thing is loaded. it's possible that the loading mechanisms have changed since then. what is your first error? that's really the only one that matters.
i know you're just trying to get a quick question in, but it's probably best to post your entire code.
the first error is line 210 'end' expected to close 'function' at line 5 'elseif'
the first error is line 210 'end' expected to close 'function' at line 5 'elseif'
so that's the syntax error i was talking about. the lua compiler is failing on the code, so the api is not even an issue.
i would suggest breaking down your handler into multiple functions based on the combat log event instead of having a ginormous if-then-else construct where you're having trouble matching ifs to ends.
If that's your whole code, you have several major problems:
1. The frame reference, event name, and event arguments are NOT set as global variables since WoW 4.0 (and it's been recommended not to use them since WoW 2.0). One consequence of this is that there is no global "this". You should be seeing several errors in the vein of "attempt to index global 'this' (a nil value)".
2. You don't have a frame, so you have nothing to call the :RegisterEvent or :SetScript methods on.
3. You should avoid creating functions in the global namespace, which is where your "HelloWorld" function currently resides. If you absolutely can't avoid it, at least give your functions better names, like "SuperMagicAddon_HelloWorld".
4. Doing a bunch of checks on the flags is pretty inefficient. I'm not sure what exactly you're trying to do, but using bit.band would probably make things a lot easier for you. Also, it looks like you're checking for the same values no matter what the combat event is, so it would be way more efficient to check once at the top of the event handler, and return out if the flags don't match something you're interested in.
is one of the most ridiculous things I've ever seen. x = select(1, ...) is exactly the same as x = ..., aside from adding the overhead of a function call for absolutely no purpose. You could cut out TWO function calls by doing this instead:
Then, when you handle each eventType, assign the remaining arguments to named variables that actually reflect their values:
if eventType == "SPELL_AURA_REMOVED" then
local spellID, spellName, spellSchool, auraType = ...
elseif eventType == "SPELL_DISPEL" then
local spellID, spellName, spellSchool, extraSpellID, extraSpellName, extraSchool, auraType = ...
5. Your giant if-then-else chain is a giant mess. The random extra blank lines and inconsistent indentation don't help your code's readability, either.
[...]
is one of the most ridiculous things I've ever seen. x = select(1, ...) is exactly the same as x = ..., aside from adding the overhead of a function call for absolutely no purpose.
When I first started coding, I also had no idea what the heck select(1, ...) was for (when I looked into other addon's code)
we (read: noobs) didn't know better I guess ><
Also, sometimes when I look at someone's indenting I can't stop thinking about if an author was on drugs while writing his code
This worked flawlessly when I played wow back in the BC. My next question is where could I find someone to hire to make this light addon a reality?
Would really love it to work like it did 2 years ago and not looking to make any type of gui, the hard coding is fine. But yea any advice on where I can hire someone to help me with this would be great!
When I first started coding, I also had no idea what the heck select(1, ...)
Also, sometimes when I look at someone's indenting I can't stop thinking about if an author was on drugs while writing his code
If that's your whole code, you have several major problems:
1. The frame reference, event name, and event arguments are NOT set as global variables since WoW 4.0 (and it's been recommended not to use them since WoW 2.0). One consequence of this is that there is no global "this". You should be seeing several errors in the vein of "attempt to index global 'this' (a nil value)".
2. You don't have a frame, so you have nothing to call the :RegisterEvent or :SetScript methods on.
i'm guessing there's probably an additional xml file that calls HelloWorld from a frame OnLoad script.
that would explain the global namespace function and the use of "this:" as a reference.
This worked flawlessly when I played wow back in the BC. My next question is where could I find someone to hire to make this light addon a reality?
Would really love it to work like it did 2 years ago and not looking to make any type of gui, the hard coding is fine. But yea any advice on where I can hire someone to help me with this would be great!
Thanks
well, lua syntax hasn't changed, so the file must have since you last used it. if the lua parser is choking on it, it would have back in bc as well. fixing the mismatched if-end blocks would be the first step.
beyond that, you could add 'local this = CreateFrame("Frame")' to the top of your file to get your started down the road to making it run. it's horribly hacky, but i get that you just want something that runs and that (i think) would get you running (again assuming you sort out your syntax error(s)).
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
function HelloWorld()
this:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
this:SetScript("OnEvent", function(self, event, ...)
local timestamp, eventType, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags = select(1, ...)
local arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11 = select(9, ...)
Is any of that wrong or has changed, the addon used to work back in BC but now it gets errors including line 1 attempt to call global helloworld (a nil value)
Ty for all the help.
here is a few lines of code from the addon...
if arg1 == 31224 then
if dstFlags ==0x30548 or dstFlags==0x10548 or dstFlags==0x20548 or dstFlags == 0x548 then
PlaySoundFile("Interface\\AddOns\\MySounds\\cloak.mp3");
end
thanks!
i know you're just trying to get a quick question in, but it's probably best to post your entire code.
Sorry sorry here is the code below. While I wrote all the if/else code and figured out how to understand the combat events, I did not write the opening code as I didn't understand how to get it started. A very nice guy on a forum helped me with that to get it all started.
I would love if someone could do that here just the opening code to declare the addon and such, I would LOVE it actually :)
here is the code:
the first error is line 210 'end' expected to close 'function' at line 5 'elseif'
so that's the syntax error i was talking about. the lua compiler is failing on the code, so the api is not even an issue.
i would suggest breaking down your handler into multiple functions based on the combat log event instead of having a ginormous if-then-else construct where you're having trouble matching ifs to ends.
1. The frame reference, event name, and event arguments are NOT set as global variables since WoW 4.0 (and it's been recommended not to use them since WoW 2.0). One consequence of this is that there is no global "this". You should be seeing several errors in the vein of "attempt to index global 'this' (a nil value)".
2. You don't have a frame, so you have nothing to call the :RegisterEvent or :SetScript methods on.
3. You should avoid creating functions in the global namespace, which is where your "HelloWorld" function currently resides. If you absolutely can't avoid it, at least give your functions better names, like "SuperMagicAddon_HelloWorld".
4. Doing a bunch of checks on the flags is pretty inefficient. I'm not sure what exactly you're trying to do, but using bit.band would probably make things a lot easier for you. Also, it looks like you're checking for the same values no matter what the combat event is, so it would be way more efficient to check once at the top of the event handler, and return out if the flags don't match something you're interested in.
5. This:
is one of the most ridiculous things I've ever seen. x = select(1, ...) is exactly the same as x = ..., aside from adding the overhead of a function call for absolutely no purpose. You could cut out TWO function calls by doing this instead:
Then, when you handle each eventType, assign the remaining arguments to named variables that actually reflect their values:
5. Your giant if-then-else chain is a giant mess. The random extra blank lines and inconsistent indentation don't help your code's readability, either.
When I first started coding, I also had no idea what the heck select(1, ...) was for (when I looked into other addon's code)
we (read: noobs) didn't know better I guess ><
Also, sometimes when I look at someone's indenting I can't stop thinking about if an author was on drugs while writing his code
Edit: btw, here are the wiki's: Bitwise operation, Bitwise Operators, BitLib, and UnitFlags
This worked flawlessly when I played wow back in the BC. My next question is where could I find someone to hire to make this light addon a reality?
Would really love it to work like it did 2 years ago and not looking to make any type of gui, the hard coding is fine. But yea any advice on where I can hire someone to help me with this would be great!
Thanks
lol
i'm guessing there's probably an additional xml file that calls HelloWorld from a frame OnLoad script.
that would explain the global namespace function and the use of "this:" as a reference.
well, lua syntax hasn't changed, so the file must have since you last used it. if the lua parser is choking on it, it would have back in bc as well. fixing the mismatched if-end blocks would be the first step.
beyond that, you could add 'local this = CreateFrame("Frame")' to the top of your file to get your started down the road to making it run. it's horribly hacky, but i get that you just want something that runs and that (i think) would get you running (again assuming you sort out your syntax error(s)).