WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Help with simple code (https://www.wowinterface.com/forums/showthread.php?t=43674)

Sythical 07-08-12 11:22 AM

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!

Rilgamon 07-08-12 11:29 AM

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 :)

Talyrius 07-08-12 11:30 AM

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.

Sythical 07-08-12 12:35 PM

Thank you both, that helped :)


All times are GMT -6. The time now is 03:12 PM.

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