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.
Post Reply
issuetracker
Prole
Posts: 1
Joined: Thu Jan 12, 2017 10:00 pm

HUMP wont restart gamestate

Post by issuetracker » Thu Jan 12, 2017 10:17 pm

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 :)

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

Re: HUMP wont restart gamestate

Post by xNick1 » Fri Jan 13, 2017 1:27 pm

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

User avatar
zorg
Party member
Posts: 2995
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: HUMP wont restart gamestate

Post by zorg » Fri Jan 13, 2017 1:44 pm

"Hi, and welcome to the forums!"

Also, please post a minimal code example where it doesn't work; that helps us help you more. :3
Me and my stuff :3True 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.

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

Re: HUMP wont restart gamestate

Post by raidho36 » Fri Jan 13, 2017 3:29 pm

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.

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

Re: HUMP wont restart gamestate

Post by Chroteus » Fri Jan 13, 2017 5:08 pm

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

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

Re: HUMP wont restart gamestate

Post by s-ol » Fri Jan 13, 2017 9:11 pm

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

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

Re: HUMP wont restart gamestate

Post by Chroteus » Wed Jan 18, 2017 7:49 pm

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.

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

Re: HUMP wont restart gamestate

Post by bartbes » Wed Jan 18, 2017 8:21 pm

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.

Post Reply

Who is online

Users browsing this forum: Jeeper and 26 guests