Hello,
i am currently making a game for a school project and i stumbled about a problem that has been bothering me. I can't seem to make the game restart. From the main.lua i use hump.gamestate to switch to the menu, then from there when a user presses the play button i again use the gamestate to switch to my game.lua where the game logic is. Now the problem:
From here, if switch to the menu again it all looks good and well but when i press play again it sends me back to the same state i was before when the game ended. I know i am probably doing something wrong so if anyone can guide me on how to restart the game with hump gamestate. Is there a way to dump all the state and then restart it? Because only using gamestate.switch() doesn't work for me.
Nice community you got here
HUMP wont restart gamestate
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: HUMP wont restart gamestate
I never used HUMP, but you could reset your variables when you press the "Play" button.
(ex. Every level you gain 1 hp, so you end up with 10 hp. When you enter the load function again you reset the hp to 0).
Otherwise call "love.load()" to reload the game once it ended
(ex. Every level you gain 1 hp, so you end up with 10 hp. When you enter the load function again you reset the hp to 0).
Otherwise call "love.load()" to reload the game once it ended
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: HUMP wont restart gamestate
"Hi, and welcome to the forums!"
Also, please post a minimal code example where it doesn't work; that helps us help you more.
Also, please post a minimal code example where it doesn't work; that helps us help you more.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: HUMP wont restart gamestate
I see nothing out of order here - if you switch state it does just that, but it doesn't reset it. You have to do that manually.
Re: HUMP wont restart gamestate
You see, the init() method used to load data is set to nil by HUMP after it's called once.
What you can do, is to change your current init() method and rename it to loadState(), for example. Then, in the init() call loadState(). Whenever you need to restart the game, call loadState().
What you can do, is to change your current init() method and rename it to loadState(), for example. Then, in the init() call loadState(). Whenever you need to restart the game, call loadState().
Github: https://github.com/chroteus
Re: HUMP wont restart gamestate
No, thats just making it way harder to use the state properly.Chroteus wrote:You see, the init() method used to load data is set to nil by HUMP after it's called once.
What you can do, is to change your current init() method and rename it to loadState(), for example. Then, in the init() call loadState(). Whenever you need to restart the game, call loadState().
It's very simple: use gamestate:enter() not gamestate:init() since the latter runs once and only once, while enter runs each time.
The documentation is pretty clear about this actually: http://hump.readthedocs.io/en/latest/ga ... -callbacks
Re: HUMP wont restart gamestate
s-ol wrote:No, thats just making it way harder to use the state properly.Chroteus wrote:You see, the init() method used to load data is set to nil by HUMP after it's called once.
What you can do, is to change your current init() method and rename it to loadState(), for example. Then, in the init() call loadState(). Whenever you need to restart the game, call loadState().
It's very simple: use gamestate:enter() not gamestate:init() since the latter runs once and only once, while enter runs each time.
The documentation is pretty clear about this actually: http://hump.readthedocs.io/en/latest/ga ... -callbacks
As far as I understood OP wants to restart the game to start a fresh game. So, :enter() won't cut it.
EDIT: To clarify my point, if he enters "pause" state while in game, it shouldn't restart the game with :enter() after unpausing.
Github: https://github.com/chroteus
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: HUMP wont restart gamestate
Ah, but that's why there's a stack of gamestates! If you push a state (then pop it again), enter isn't called, resume is called.Chroteus wrote: EDIT: To clarify my point, if he enters "pause" state while in game, it shouldn't restart the game with :enter() after unpausing.
Who is online
Users browsing this forum: Google [Bot] and 4 guests