## HUMP wont restart gamestate

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
issuetracker
Prole
Posts: 1
Joined: Thu Jan 12, 2017 10:00 pm

### HUMP wont restart gamestate

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

xNick1
Party member
Posts: 265
Joined: Wed Jun 15, 2016 8:27 am
Location: Rome, Italy

### 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
Currently working on a lucid dreaming adventure called Aarstider: http://bit.ly/2mXmgPI

zorg
Party member
Posts: 2995
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.
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.

raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

### 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.

Chroteus
Citizen
Posts: 87
Joined: Wed Mar 20, 2013 7:30 pm

### 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().

s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

### Re: HUMP wont restart gamestate

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().
No, thats just making it way harder to use the state properly.

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

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
baby:hurt(me)
end

Chroteus
Citizen
Posts: 87
Joined: Wed Mar 20, 2013 7:30 pm

### Re: HUMP wont restart gamestate

s-ol wrote:
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().
No, thats just making it way harder to use the state properly.

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.

bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

### Re: HUMP wont restart gamestate

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.
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.

### Who is online

Users browsing this forum: No registered users and 38 guests