Thread Tools Display Modes
04/21/17, 06:08 PM   #1
Rugnir_viking
Join Date: Apr 2017
Posts: 3
Question Debugging with d() not working?

I seem to have a huge problem with following some of the basic addon tutorials.

Originally i thought the code was being complied but not run at all (errors fired when I made syntax error but no output whatsoever)

But it turns out that when I forged ahead anyway, xml and all that jazz works fine. It just seems that no kind of d() debug output actually appears in my chat

Its been annoying me for ages now.

Any solutions?
  Reply With Quote
04/21/17, 06:12 PM   #2
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
Does this cover it?
  Reply With Quote
04/21/17, 06:22 PM   #3
Rugnir_viking
Join Date: Apr 2017
Posts: 3
Unfortunately it does not seem to cover it
After a bit more experimentation, I believe its not entirely to do with d() and perhaps my lack of understanding, but here is my code

I'm expecting when I enter/exit combat for stuff to appear in chat

here is my attempt at code

Lua Code:
  1. function Initialise()
  2.     EVENT_MANAGER:RegisterForEvent("TestAddon1", EVENT_PLAYER_COMBAT_STATE, combatStatusChanges)
  3. end
  4.  
  5. function combatStatusChanges()
  6.     -- literally anything sould cause it to debug output
  7.     d("help me")
  8. end
  9.  
  10. function addOnInit(event, addonName)
  11.   if addonName == "TestAddon1" then
  12.     Initialise()
  13.   end
  14. end
  15.  
  16.  
  17. EVENT_MANAGER:RegisterForEvent("TestAddon1", EVENT_ADD_ON_LOADED, addOnInit)
  Reply With Quote
04/21/17, 07:17 PM   #4
ArctixFox
AddOn Author - Click to view addons
Join Date: Apr 2017
Posts: 2
maybe try

Lua Code:
  1. function combatStatusChanges(eventCode, inCombat)

so the signature of the function matches what the caller expects. I haven't tried it, but...
  Reply With Quote
04/21/17, 07:18 PM   #5
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
You should think about using local variables and function names, or put the functions and variables in a table that is only used in your addon.
Otherwise you could overwrite a variable/function of another addon that got the same name

If you use local functions the order of the functions and variables must be correct! lua is interpreting the function/variable names from top to bottom so you need to put functions that are local and will be called BEFORE (more to the top) the place where you call it.

Lua Code:
  1. local function combatStatusChanges(eventCode, inCombat)
  2.     -- literally anything sould cause it to debug output
  3.     d("In combat: " .. tostring(inCombat))
  4. end
  5.  
  6. local function Initialise()
  7.     EVENT_MANAGER:RegisterForEvent("TestAddon1", EVENT_PLAYER_COMBAT_STATE, combatStatusChanges)
  8. end
  9.  
  10.  
  11. local function addOnInit(event, addonName)
  12.   if addonName == "TestAddon1" then
  13.     Initialise()
  14.   end
  15. end
  16.  
  17.  
  18. EVENT_MANAGER:RegisterForEvent("TestAddon1", EVENT_ADD_ON_LOADED, addOnInit)

This code should bring you your message "help me" to the chat.
Be sure to check if the chat tabs you are using got the "system" messages activated in the tab options!
right click the tab and choose options, then have a look at the middle-right and mark the checkbox for system and say close.

Last edited by Baertram : 04/21/17 at 07:21 PM.
  Reply With Quote
04/22/17, 05:37 AM   #6
Rugnir_viking
Join Date: Apr 2017
Posts: 3
Thanks for all you guys help.

There is no system checkbox in any chat tab options. This is a completely vanilla install.

I did however find the solution. I was mixing names in the addon, so I tried something that didn't have spaces so the folder and stuff would all be the same and that worked.

For future reference, not specifying the arguments to the event function does work.
  Reply With Quote
04/23/17, 08:28 AM   #7
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
The system chat tab options checkbox is there in the total vanilla interface of the game, running no addons.
Right click the chat tab, choose options and check the possibilities to enable/disbale specific "chat channels" for the given chat's tab.
  Reply With Quote
04/23/17, 09:11 AM   #8
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
No, it's pChat ^^
  Reply With Quote
04/23/17, 09:45 AM   #9
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
By default, the system option is only in the first tab.
  Reply With Quote
04/23/17, 01:22 PM   #10
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Oh, ok. Thanks Rhyono & Ayantir.
Only had checked the first tab
  Reply With Quote

ESOUI » AddOns » AddOn Search/Requests » Debugging with d() not working?

Thread Tools
Display Modes

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