Hello, and welcome.
First, I suggest you to use the Lua Highlighter in the forum (the last icon).
Then, few syntaxes mistakes
Lua 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)
- 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:
local LempsAddon = {}
LempsAddon.name = "LempsAddon"
LempsAddon.version = "1.0"
LempsAddon.inCombat = false
function LempsAddon.CombatStateChanged(event, combatState)
LempsAddon.inCombat = combatState
if LempsAddon.inCombat then
d("fight")
else
d("no fight")
end
end
function LempsAddon.OnAddOnLoaded(event, addonName)
if addonName == LempsAddon.name then
LempsAddon.inCombat = IsUnitInCombat("player")
EVENT_MANAGER:RegisterForEvent("LempsAddon", EVENT_PLAYER_COMBAT_STATE, LempsAddon.CombatStateChanged)
EVENT_MANAGER:UnregisterForEvent("LempsAddon", EVENT_ADD_ON_LOADED)
end
end
EVENT_MANAGER:RegisterForEvent("LempsAddon", EVENT_ADD_ON_LOADED, LempsAddon.OnAddOnLoaded)