Addon Structure Issue

Lord it’s been too long since I did this. I’m working my way back into addon coding incrementally, so forgive me if this doesn’t look like a “real” addon yet. I’m just working on relearning the necessary structures.

MacroParse.toc

## Interface: 90100
## Title: MacroParser
## Author: KaldaraWorks
## Version: 1.0.0
## SavedVariables: MP_SavedData

MP_Initialize.lua
MacroParser.lua

MP_Initialize.lua

local _, MP_Env		= ...

MP_Env				= {}
MP_Env.functions	= {}

local f				= MP_Env.functions

function f.Initialization()
	
	local frame				= CreateFrame('Frame')
	frame:RegisterEvent('PLAYER_ENTERING_WORLD')
	
	frame:SetScript("OnEvent", function(self, event, ...)
		if     (event == 'PLAYER_ENTERING_WORLD') then
			MP_SavedData	= "I saved this, too"
		end
		
	end)

end

MacroParser.lua

local _, MP_Env		= ...

local f				= MP_Env.functions

f.Initialization()

This fails with 1x MacroParser\MacroParser-1.0.0.lua:5: attempt to index local 'f' (a nil value) as an error message.

If I move the f.Initialization() line in as the last line in MP_Initialize.lua it works fine.

I thought that the local _, MP_Env = ... line carried data from one module to the other in a way that made the part I’ve called MP_Env scoped across the addon modules. I defined local f in both the MP_Initialize.lua and MacroParser.lua modules. What am I doing wrong there?

Yes, i could leave that line at the end of MP_Initialize but that wouldn’t help me understand how to do what I am pretty sure I ought to be able to do here - define an addon-scoped variable that can contain functions defined in one module for use in another.

local _, MP_Env		= ...

MP_Env				= {}

You’ve assigned MP_ENV the addons private table and then right after, assigned it as a new local table.

Get rid of the
MP_Env = {}

<Do’T!>

Man, I knew it as something simple and stupid.

I’m working on an in-game replacement for the now-very-out-of-date Explain-o-Matic website.

Wish me luck. :slight_smile:

1 Like

Hey man,

Someone’s been trying to reach you about an alternative movement method regarding the forum post you made about your girlfriend a while back.

Reddit thread here: https://www.reddit.com/r/wow/comments/ocsh8d/looking_for_someone_to_pass_information_about

3 Likes

Thanks, Asmonswole - I read that.

Sadly, the GF deteriorated enough that I had to send her back to family. I just couldn’t keep up with her needs given that I’m looking at some health issues myself but I really do appreaciate the “above and beyond” nature of the post.

:slight_smile:

1 Like