Hi all. I'm using HUMP's gamestates library and my code is getting a little unruly in it's length. I have certain functions isolated in their own .lua files to keep things organized, which is a start, but I'm wondering how I can keep individual gamestates in their own files as well to keep things tidy and to save time hunting around my code. Fore example, how can I isolate menu and game into their own .lua files?
Gamestate = require "gamestate"
local menu = {}
local game = {}
function love.load()
Gamestate.registerEvents()
Gamestate.switch(menu)
end
function menu:enter()
-- menu load out
end
function menu:update(dt)
-- many lines of code
end
function menu:draw()
-- many lines of code
end
function game:enter()
-- many lines of code
end
function game:update(dt)
-- many lines of code
end
function game:draw()
-- many lines of code
end
Last edited by hiccupface on Wed May 20, 2015 8:37 pm, edited 1 time in total.
Gamestate = require "gamestate"
local game = require"states.game"
local menu = require"states.menu"
function love.load()
Gamestate.registerEvents()
Gamestate.switch(menu)
end
local game = {}
function game:enter()
-- many lines of code
end
function game:update(dt)
-- many lines of code
end
function game:draw()
-- many lines of code
end
return game
Weird - that's what I thought, but it does't seem to be working for me. My game loads fine, and after my first keypress which transitions me from menuscreen to instructions screen I get the error below. (fyi, I'm testing by creating instructions.lua as a separate file)
gamestate.lua:42: attempt to index local 'to' (a boolean value)
Traceback
gamestate.lua: 84 in function '__index'
gamestate.lua: 42 in function 'switch'
main.lua:111: in function <main.lua:109> <--- this is where I'm requesting the scene switch
I have instructions = require'instructions' in my main.lua file and all of my instructions functions (enter, update,draw) in instructions.lua, as well, local instructions = {} at the very top.
I could share my code, though it will probably burn your eyes, haha.