how to import classes from a file (middleclass)
Posted: Mon Dec 23, 2024 12:57 am
I'm using the middleclass library, and I have my classes and my main.lua file separated. I'm trying to figure out how to import classes from the objects.lua file to the main.lua file.
this is my main.lua script, I'm new to lua, so I'm not really sure how importing things with require works
the code works when it isn't separated into two separate files, this is the error I get when i try to run the code
this is my main.lua script, I'm new to lua, so I'm not really sure how importing things with require works
Code: Select all
local class = require "middleclass"
local objects = require "objects"
updateOrder = {} --every object in this array will have its :update(delta) function called in love.update(delta)
drawOrder = {} --similar to update order, but for drawing. its function is :draw(), and it's called in love.draw
local player = Player:new(0,0) --this is where the error occurs, it doesn't have the Player class since I'm not sure how to import the classes from the objects file yet.
player:add()
function love.update(delta)
for i=1,#updateOrder,1 do
updateOrder[i]:update(delta)
end
end
Code: Select all
Error
main.lua:8: attempt to index global 'Player' (a nil value)
Traceback
[love "callbacks.lua"]:228: in function 'handler'
main.lua:8: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'