Thread Tools Display Modes
01/09/22, 06:38 PM   #1
olongjohnson
Join Date: Dec 2021
Posts: 3
Question attempt to index a nil value - following tutorial issue

Okay I am completely new and have probably a total brain fart mistake here, but I cannot figure out what I'm doing wrong following the tutorial here: https://wiki.esoui.com/Writing_your_first_addon

I am at the point where FooAddon should be outputting to console when I enter and leave combat, but the line self.inCombat = IsUnitInCombat("player") in FooAddon:Initialize() is throwing an error:

user:/AddOns/FooAddon/FooAddon.lua:6: attempt to index a nil value
stack traceback:
user:/AddOns/FooAddon/FooAddon.lua:6: in function 'FooAddon:Initialize'
user:/AddOns/FooAddon/FooAddon.lua:13: in function 'FooAddon.OnAddonLoaded'
<Locals> event = 65536, addonName = "FooAddon" </Locals>

I've checked for typos - to the point of copy pasting in code from the tutorial, but cannot get this solved. I called and saved IsUnitInCombat("player") to a test variable & printed it to console fine on reload, so I'm assuming my 'self.inCombat' initialization is wrong somehow. I tried initializing the inCombat variable earlier/outside of the initialization function for FooAddon, but that didn't work either.

The only thing I can think to go on now is that this error pops up about 10 times at the bottom of my debug log every reload for various addons, seeming to stem from 'Failed to create control 'LibCustomMenuSubmenu'. Duplicate Name.' following that, there's a bunch of following 'attempt to index a nil value' errors. I'll post a screenshot of my logger output & current lua file.
Attached Thumbnails
Click image for larger version

Name:	indexnilLog.PNG
Views:	235
Size:	635.8 KB
ID:	1437  
Attached Files
File Type: lua FooAddon.lua (670 Bytes, 206 views)
  Reply With Quote
01/09/22, 06:55 PM   #2
olongjohnson
Join Date: Dec 2021
Posts: 3
I fixed the 'duplicate library' error, but still get all the 'attempt to index a nil value' errors.
Attached Thumbnails
Click image for larger version

Name:	indexnilLog2.PNG
Views:	193
Size:	561.8 KB
ID:	1439  
  Reply With Quote
01/09/22, 07:24 PM   #3
olongjohnson
Join Date: Dec 2021
Posts: 3
Cool

WEW

yeah it was something stupid...

I was using OnAddonLoaded instead of OnAddOnLoaded.

As well as I had FooAddon.Initialize() instead of FooAddon:Initialize() in the OnAddOnLoaded function.
  Reply With Quote
01/10/22, 03:00 AM   #4
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,960
The : notation should only be used if you define FooAddon as object via ZO_Object. It's a kind of Object Oriented approach where ZO_WhatEver is the class defining the objects attributes and functions and via ZO_WhatEver:New(...) you define the object.
e.G. SMITHING = ZO_Smithing:New() for the crafting tables.

If you do not use OO and you only got a table for FooAddon, like FooAddon = {}, you should not use : but simply . notation.

Only if you use ZO_Object and ZO_SubClass properly to define a reusable class for your addon, and then create an object for your addon using your addon class, the : notation would be correct and the self pointer would work as intended.
You can have a look at the addon Circonians MyStatus for an example how the class & object addon could be created. But this is complicated and not needed for most simple addons! Just use a normal table and . notation for the start.

That tutorial you follow might need an update to that.

Last edited by Baertram : 01/10/22 at 03:07 AM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » attempt to index a nil value - following tutorial issue

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