[Solved] Re-load a gamestate in HUMP

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
User avatar
NickRock
Citizen
Posts: 76
Joined: Thu Dec 25, 2014 9:33 pm
Location: Earth
Contact:

[Solved] Re-load a gamestate in HUMP

Post by NickRock »


EDIT:

The problem is solved thanks everyone! :D


I'm making an arcade game where when you lose you press a key to go back to the menu, when you go back to the "game" state it doesn't re-load it again but continues from where its left of

How can I fix that?
Last edited by NickRock on Sat Dec 12, 2015 8:43 am, edited 2 times in total.
Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeooow!!
User avatar
pgimeno
Party member
Posts: 3548
Joined: Sun Oct 18, 2015 2:58 pm

Re: Re-load a gamestate in HUMP

Post by pgimeno »

You'll need a way to initialize the game state externally, and call it when entering your game (and maybe in other places like after game over) rather than when switching states.

Or have a flag that says whether it needs initialization on state entry, and set it on game load and on game over.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Re-load a gamestate in HUMP

Post by vrld »

state:enter() is called whenever you enter a gamestate, so you have to place to reset the state there, for example:

Code: Select all

function game:enter()
    self.level = Levels.load("level-01.map")
    self.player = Player(self.level.spawnPoint)
    self.score = 0
    ...
end
There is also a function that you can use when you need to do stuff only once before entering the state: state:init(). For example, you could load the map in state:init() and just reset everything in state:enter() to avoid reading in the level every time:

Code: Select all

function game:init() -- only called once
    self.level = Levels.load("level-01.map")
end

function game:enter() -- called every time the state is entered
    self.level:reset()
    self.player = Player(self.level.spawnPoint)
    self.score = 0
    ...
end
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
NickRock
Citizen
Posts: 76
Joined: Thu Dec 25, 2014 9:33 pm
Location: Earth
Contact:

Re: Re-load a gamestate in HUMP

Post by NickRock »

I made a simple saving library for my game and it seems like it doesn't load the new highscore when I call the game:init() function
If you guys could help me find where the problem is that would be great.

Thanks.
Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeooow!!
Post Reply

Who is online

Users browsing this forum: No registered users and 32 guests