"Substates" really aren't necessary IMO. I think you're trying to use more layers than you need. You could make each state a table with load, update and draw methods, as well as an ID. You could make another table, with a table inside it to store all states, and a master flag that determines which state is to be loaded, updated, and drawn, like so:
Code: Select all
Master = {states = {-- All states are inserted here}}
Master.current = Example.ID
function Master:addState(S) -- 'S' is the state you want to add to the master
if S.ID then -- Ensure the state has an ID
table.insert(Master.states, S)
S:load() -- If this was plugged into main, states may conflict with one another
else
return end
end
-- -- --
function love.update(dt)
for i,v in pairs(Master.states) do -- Find the current state and call it's update method (do the same for love.draw)
if Master.current = v.ID then
v:update()
end
end
end
There's a lot more you could do with this idea, this is just the basic premise. Hope this helped!
EDIT: just to clarify, you could do anything within the load, update, and draw methods. If you needed to call any other functions, you could make those calls in the methods for the state(s) you needed them. That could be loading levels, drawing a menu, etc..
"I am a tomato. My favorite food is tomatoes. Tomatoes are the best. I eat them everyday. I love to hear them scream."