View Single Post
05/11/20, 09:46 AM   #1
QuantumPie
AddOn Author - Click to view addons
Join Date: Sep 2019
Posts: 32
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.
  Reply With Quote