Thread Tools Display Modes
07-08-12, 11:22 AM   #1
Sythical
A Defias Bandit
Join Date: Jul 2012
Posts: 2
Help with simple code

Hey, I've just started learning Lua and tried to make a simple addon for my rogue, but it didn't work. I tried debugging and I think the problem is in this part of the code:

Lua Code:
  1. local EventFrame = CreateFrame("Frame")
  2.  
  3. EventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
  4. EventFrame:SetScript("OnEvent", test_function);
  5.  
  6. function test_function(self, event, ...)
  7.     ChatFrame1:AddMessage("COMBAT_LOG_EVENT_UNFILTERED");
  8. end

What I expect this code to do is spam my chat box for each COMBAT_LOG_EVENT_UNFILTERED event it detects, but nothing happens. I can't understand what I'm doing wrong and will greatly appreciate any assistance. Thank you!
  Reply With Quote
07-08-12, 11:29 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
Code is "read" from top to bottom.
So at line 4 you set 'nil'. Move your function up or the setscript down.
And make it local
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
07-08-12, 11:30 AM   #3
Talyrius
An Onyxian Warder
 
Talyrius's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 363
Lua Code:
  1. local EventFrame = CreateFrame("Frame")
  2.  
  3. local function test_function(self, event, ...)
  4.     ChatFrame1:AddMessage("COMBAT_LOG_EVENT_UNFILTERED")
  5. end
  6.  
  7. EventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
  8. EventFrame:SetScript("OnEvent", test_function)

Have you tried defining the function before you try to reference it?

EDIT: Rilgamon beat me to it.
  Reply With Quote
07-08-12, 12:35 PM   #4
Sythical
A Defias Bandit
Join Date: Jul 2012
Posts: 2
Thank you both, that helped
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help with simple code


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