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.
