ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   attempt to index a nil value - following tutorial issue (https://www.esoui.com/forums/showthread.php?t=10040)

olongjohnson 01/09/22 06:38 PM

attempt to index a nil value - following tutorial issue
 
2 Attachment(s)
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.

olongjohnson 01/09/22 06:55 PM

1 Attachment(s)
I fixed the 'duplicate library' error, but still get all the 'attempt to index a nil value' errors.

olongjohnson 01/09/22 07:24 PM

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.

Baertram 01/10/22 03:00 AM

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.


All times are GMT -6. The time now is 12:20 PM.

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