Some clarification on HUMP.gamestate needed [Solved]
Posted: Wed Jul 30, 2014 6:12 pm
So, i started using hump.gamestate to give my prototype a structure, but i'd like to have some clarification about the using of it (yes i've read the documentation on the github page) inside my code.
I want to have, for now, 2 states: menu and world_map. Each one with its own lua file. In my main.lua i've got something like this:
Now, with what's written now, when I call gamestate.switch(menu) i go to initialisation of the menu and then I enter its state, where the game updates what needs to be updated (if its present the menu:update(dt) function) and draw what needs to be drawn (menu:draw(), both these functions are called thanks to gamestate.registerEvents(), which looks for callbacks and execute them). For now, everything is fine menu is displayed and if i run this line: if gamestate.current() == menu then print("I'm in the menu") end it actually prints.
Now, I want to switch state and would like to go the world_map when i press enter and for this purpose I write this:
Now, shouldn't this bring me to the world_map state? For the same reason as before gamestate.registerEvent() will call menu:keyreleased(key) whenever I get an input. And this is my problem: i'm stuck in the menu state and doesn't recognize Enter as the proper input.
Can anyone give me an advice/example on how I should use properly HUMP.gamestate and what I'm missing in my current code (yes, they are just some snippets, but i thought it would be enough for my issue, i can give a .love if needed)?
I want to have, for now, 2 states: menu and world_map. Each one with its own lua file. In my main.lua i've got something like this:
Code: Select all
module(..., package.seeall)
require("entities")
require("menu")
require("world_map")
gamestate = require "hump.gamestate"
function love.load()
gamestate.registerEvents()
gamestate.switch(menu)
end
function love.update(dt)
entities:update(dt)
end
function love.keyreleased(key)
if key == "escape" then
love.event.quit()
end
end
function love.draw()
end
function love.quit()
print("Thanks for playing!")
end
Now, I want to switch state and would like to go the world_map when i press enter and for this purpose I write this:
Code: Select all
function menu:keyreleased(key)
if key == 'enter' then
print("I pressed enter")
gamestate.switch(world_map)
end
end
Can anyone give me an advice/example on how I should use properly HUMP.gamestate and what I'm missing in my current code (yes, they are just some snippets, but i thought it would be enough for my issue, i can give a .love if needed)?