I couldn't figure this myself, so i need professional help.
i'll use several gamestates, and to keep it organized, i want to put the callbacks for each gamestate on a different lua file.
But when i do that, i get an error.
Lets go to some example code:
Code: Select all
titlescreen = Gamestate.new()
in_game = Gamestate.new()
function love.load()
Gamestate.registerEvents()
Gamestate.switch(titlescreen)
end
function titlescreen.draw()
love.graphics.print("G A M E S E L E C T", 300, 100)
end
function in_game.draw()
love.graphics.print("I N G A M E", 300, 100)
end
function love.keypressed(key)
if key == "1" then Gamestate.switch(titlescreen) end
if key == "2" then Gamestate.switch(in_game) end
end
If i place the function titlescreen.draw() in a different file and require it, i get an error message.
So, is there a way to do it?