Page 1 of 1
[Solved] Re-load a gamestate in HUMP
Posted: Sun Dec 06, 2015 9:19 am
by NickRock
EDIT:
The problem is solved thanks everyone!
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?
Re: Re-load a gamestate in HUMP
Posted: Sun Dec 06, 2015 4:33 pm
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.
Re: Re-load a gamestate in HUMP
Posted: Sun Dec 06, 2015 8:28 pm
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
Re: Re-load a gamestate in HUMP
Posted: Mon Dec 07, 2015 1:11 pm
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.