This might come across as a dumb question, but I have been beating my head against the wall for the past hour trying to figure this out to no avail.
I have created a separate file (LevelData.lua) that exists in the same directory as the code that runs the main logic of the game. Roughly speaking, LevelData is structured like this:
local levelData = {}
-- Define levels as a table
levelData.levels = {
...
}
-- Active level (initially nil)
levelData.activeLevel = nil
-- Method to set the active level
function levelData:setActiveLevel(levelIndex)
self.activeLevel = self.levels[levelIndex]
end
-- Method to get the active level
function levelData:getActiveLevel()
return self.activeLevel
end
return levelData
Now, in my game logic function, I am trying to import and interract with the data like this:
import "LevelData"
print(LevelData.levels[1])
However, when I do this, I run into an error, "Attempt to index a nil value (global 'LevelData').
I have triple checked that my filenames and folder structure is correct. LevelData.lua should be returning at the end of the function, but something is going wrong.