ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Can't figure out why d() isn't working from tutorial code (https://www.esoui.com/forums/showthread.php?t=9139)

QuantumPie 05/11/20 09:46 AM

Can't figure out why d() isn't working from tutorial code
 
Hey! I'm trying to get started with developing my own addon and when I tried to use d() to print output I wasn't getting anything. After doing some digging I realized it won't print in initialized so I moved it to an event with no luck. I then directly copied the tutorial "Writing your first add-on" which also wouldn't print anything to the chat window. The addon is enabled and the description / author matches the manifest file. My file structure is

- DamageType/
- DamageType.lua
- DamageType.txt

My manifest file contains:
Code:

## Title: Damage Type Tracker
## Author: QuantumPie
## AddOnVersion: 001
## Version: 0.0.1
## APIVersion: 100030
## Description: Tracks the damage type of incoming damage so your CP can be optomized

DamageType.lua

And the lua file contains:

Lua Code:
  1. FooAddon = {}
  2.  
  3. FooAddon.name = "FooAddon"
  4.  
  5.  
  6. -------------------------------------
  7. -- Initialize the addon.
  8. -------------------------------------
  9. function FooAddon.OnAddOnLoaded(event, addonName)
  10.     if addonName == FooAddon.name then
  11.         FooAddon:Initialize()
  12.     end
  13. end
  14.  
  15. -------------------------------------
  16. -- Load saved variables and register the event listeners.
  17. -------------------------------------
  18. function FooAddon:Initialize()
  19.     FooAddon.inCombat = IsUnitInCombat("player")
  20.     EVENT_MANAGER:RegisterForEvent(FooAddon.name, EVENT_PLAYER_COMBAT_STATE, FooAddon.OnPlayerCombatState)
  21. end
  22.  
  23. function FooAddon.OnPlayerCombatState(_, inCombat)
  24.     -- The ~= operator is "not equal to" in Lua.
  25.     d("In event!")
  26.     if inCombat ~= FooAddon.inCombat then
  27.         FooAddon.inCombat = inCombat
  28.    
  29.         if inCombat then
  30.             d("Entering combat.")
  31.         else
  32.             d("Exiting combat.")
  33.         end
  34.    
  35.     end
  36. end
  37.  
  38. EVENT_MANAGER:RegisterForEvent(FooAddon.name, EVENT_ADD_ON_LOADED, FooAddon.OnAddOnLoaded)

Which is a slightly modified version of the tutorial as I was troubleshooting. Is there a typo somewhere I am missing? I'd think that wouldn't be the case since it still didn't work when I had a direct copy of the code from the above tutorial.

Baertram 05/11/20 10:02 AM

Just a guess:

Are you testing with ONLY your addon active? If not: Do so please!
Other addons could intercept the messages of the chat.
e.g. LibDebugLogger -> Will show the d messages in the DebugLogViewer addon (if you got that one installed).

After reviewing your code:
EVENT_ADD_ON_LOADED is fired BEFORE the chat is ready!
So you need to use EVENT_PLAYER_ACTIVATED to see the chat messages.
Or an addon like pChat which enables to read these messages in the system chat channel as well.

OR you use the library mentioned above.
LibDebugLogger + the addon DebugLogViewer.

Once enabled go to the settings of DebugLogViewer and enable the Stack traceback setting and output of the messages you send via d() before the chat is ready, as well as a list of the loaded addons and their order, should be shown in the quick log and the debug log viewer UI.

Scootworks 05/11/20 10:17 AM

your folder/file name is different like your addon name. that’s why it doesn’t work

QuantumPie 05/11/20 10:19 AM

I certinanly had those installed. I enabled stack traces and set the log level to debug but I don't see any of my d() outputs in either the chat panel or the log window

QuantumPie 05/11/20 10:20 AM

Quote:

Originally Posted by Scootworks (Post 41100)
your folder/file name is different like your addon name. that’s why it doesn’t work

They look the same to me

EDIT:
Scratch that out. I see what you mean. That fixed it! Thanks.

Scootworks 05/11/20 11:47 AM

Quote:

Originally Posted by QuantumPie (Post 41102)
They look the same to me

EDIT:
Scratch that out. I see what you mean. That fixed it! Thanks.

good :-)
don’t forget to read this page: https://wiki.esoui.com/Addon_manifest_(.txt)_format

Baertram 05/11/20 11:54 AM

Just as a hint for the others:
FooAddon.name = "FooAddon" will not work in EVENT_ADD_ON_LOADED checks if your folder and txt filename will be different than FooAddon (e.g. DamageType)


All times are GMT -6. The time now is 11:41 AM.

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