THE PROBLEM
I'm trying to refactor my old AddOn into multiple files.
When I run `> lua MyAddon.lua` from the command line, it runs as expected, spitting out "Hello World".
However, I get the familiar "function expected instead of nil" error when the UI loads.
My directory structure:
Code:
Elder Scrolls Online\live\AddOns
|
+-- MyAddon\
|
+-- MyAddon.lua
|
+-- MyDirectory\
|
+--MyFile.lua
`MyAddon.lua` contains
Lua Code:
local myTestImport = require "MyDirectory/MyFile" -- Exception: function expected instead of nil
print(myTestImport)
And `MyFile.lua` contains
THE SOLUTION
There was more wrong with my code than I thought. Here's what worked:
`MyAddon.txt` contains
Code:
## Title: MyAddon
## Author: Kronn8
## APIVersion: 100026
MyDirectory\MyFile.lua
FreeMyInventory.lua
`MyAddon.lua` contains
Lua Code:
MyAddon = MyAddon or {}
MyAddon.name = "MyAddon"
-- Load files (optional, but otherwise, you'll have to use MyAddon.MyFile each time you want to use MyFile)
local MyFile = MyAddon.MyFile
function MyAddon:confirmStartup()
d(MyFile)
end
EVENT_MANAGER:RegisterForEvent(MyAddon.name, EVENT_PLAYER_ACTIVATED, MyAddon.confirmStartup)
And `MyFile.lua` contains
Lua Code:
MyAddon = MyAddon or {}
local message = "Hello World"
MyAddon.MyFile = message