Thread Tools Display Modes
07/08/16, 05:19 PM   #1
Lagencie
AddOn Author - Click to view addons
Join Date: Jul 2016
Posts: 7
Help for a new Addon Programmer

Hello Guys,

i feel kind of stupid ... i dont even get the "Writing_your_first_addon" to work ...

Code:
LempsAddon = {}
LempsAddon.name = "LempsAddon"
LempsAddon.version = "1.0"
local LempsAddon.inCombat = false

local function LempsAddon.CombatStateChanged(combatState)
	self.inCombat = combatState
	if self.inCombat then
		d("fight")
	else
		d("no fight")
	end
end

local function LempsAddon:Initialize(event, addon)
	self.inCombat = IsUnitInCombat("player")
	EVENT_MANAGER:RegisterForEvent("LempsAddon", EVENT_PLAYER_COMBAT_STATE, LempsAddon.CombatStateChanged)
end

local function LempsAddon.OnAddOnLoaded(event, addonName)
  if addonName == LempsAddon.name then
    LempsAddon:Initialize()
  end
end

EVENT_MANAGER:RegisterForEvent("LempsAddon", EVENT_ADD_ON_LOADED, LempsAddon.OnAddOnLoaded)
This is my code but it just doesnt work ... I dont even get where this code would be able to not work ... I see no Text output to the chat (debug) at all
  Reply With Quote
07/08/16, 06:33 PM   #2
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 409
First, did you /reloadui? It's simple, but it can be easy to forget to do. Does your addon appear on the list off addons?

If you did do that, and it's still not working: Did you see any lua errors? If so, read it. It's often a lot of help in figuring out what went wrong and what you need to fix.

If there's no lua error at all, then it's something else. Check to make sure that the name of the addon matches the folder name.

LempsAddon.name = "LempsAddon" -- "LempsAddon MUST be written in exactly the same way as the name of the folder that the addon is contained in.

Also check to make sure that the name of the manifest (.txt) file matches the folder name. Open the manifest file and check that the main.lua (or whatever it's called) is listed in the manifest file. Make sure you aren't missing anything else in it.

If you download pChat, you can also see d() statements placed in the OnAddonLoaded function. If you don't have it, I suggest you do get it, and then place a d() statement right at the start of the function, and one inside the if statement. Place a d() at the start of the CombatStateChanged function too. Basically, you want to see if anything runs, and if something does, but some don't, that can help figure out what's going wrong. (just make sure to take them out later!)
  Reply With Quote
07/08/16, 07:14 PM   #3
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Hello, and welcome.

First, I suggest you to use the Lua Highlighter in the forum (the last icon).

Then, few syntaxes mistakes


Lua Code:
  1. LempsAddon = {}
  2. LempsAddon.name = "LempsAddon"
  3. LempsAddon.version = "1.0"
  4. local LempsAddon.inCombat = false
  5.  
  6. local function LempsAddon.CombatStateChanged(combatState)
  7.     self.inCombat = combatState
  8.     if self.inCombat then
  9.         d("fight")
  10.     else
  11.         d("no fight")
  12.     end
  13. end
  14.  
  15. local function LempsAddon:Initialize(event, addon)
  16.     self.inCombat = IsUnitInCombat("player")
  17.     EVENT_MANAGER:RegisterForEvent("LempsAddon", EVENT_PLAYER_COMBAT_STATE, LempsAddon.CombatStateChanged)
  18. end
  19.  
  20. local function LempsAddon.OnAddOnLoaded(event, addonName)
  21.   if addonName == LempsAddon.name then
  22.     LempsAddon:Initialize()
  23.   end
  24. end
  25.  
  26. EVENT_MANAGER:RegisterForEvent("LempsAddon", EVENT_ADD_ON_LOADED, LempsAddon.OnAddOnLoaded)

  • line 1: Your variable is leaked. you should add local before
  • line 3: Your variable is unused. please avoid it.
  • line 4: It can't work. local must be followed with a new var name. Here you write a sub element of your variable. It should be local inCombat = false or LempsAddon.inCombat = false
  • line 6: same problem. local function must be followed with the name a new variable. It's local function CombatStateChanged(combatState) or function LempsAddon.CombatStateChanged(combatState). You also forget the event parameter.
  • line 7: Your variable LempsAddon is not an object. self don't work. it's LempsAddon.inCombat = combatState
  • line 8: same as line 7
  • line 15: same as line 6
  • line 16: same as line 7
  • line 17: should reflect your choice due to the error in line 6
  • line 20: same as line 6/15
  • line 22: should reflect the change due to the error in line 15
  • line 26: should reflect the change due to the error in line 20


My code (I also added the unregistration of your addon). :
Lua Code:
  1. local LempsAddon = {}
  2. LempsAddon.name = "LempsAddon"
  3. LempsAddon.version = "1.0"
  4. LempsAddon.inCombat = false
  5.      
  6. function LempsAddon.CombatStateChanged(event, combatState)
  7.     LempsAddon.inCombat = combatState
  8.     if LempsAddon.inCombat then
  9.         d("fight")
  10.     else
  11.         d("no fight")
  12.     end
  13. end
  14.      
  15. function LempsAddon.OnAddOnLoaded(event, addonName)
  16.     if addonName == LempsAddon.name then
  17.  
  18.         LempsAddon.inCombat = IsUnitInCombat("player")
  19.  
  20.         EVENT_MANAGER:RegisterForEvent("LempsAddon", EVENT_PLAYER_COMBAT_STATE, LempsAddon.CombatStateChanged)
  21.         EVENT_MANAGER:UnregisterForEvent("LempsAddon", EVENT_ADD_ON_LOADED)
  22.     end
  23. end
  24.      
  25. EVENT_MANAGER:RegisterForEvent("LempsAddon", EVENT_ADD_ON_LOADED, LempsAddon.OnAddOnLoaded)

Last edited by Ayantir : 07/08/16 at 07:45 PM.
  Reply With Quote
07/08/16, 09:04 PM   #4
Lagencie
AddOn Author - Click to view addons
Join Date: Jul 2016
Posts: 7
lol, thanks ... so much small things wrong ... works now
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Help for a new Addon Programmer


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