[Solved] Re-load a gamestate in HUMP
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Solved] Re-load a gamestate in HUMP
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?
Last edited by NickRock on Sat Dec 12, 2015 8:43 am, edited 2 times in total.
Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeooow!!
Re: Re-load a gamestate in HUMP
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.
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
state:enter() is called whenever you enter a gamestate, so you have to place to reset the state there, for example:
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:enter()
self.level = Levels.load("level-01.map")
self.player = Player(self.level.spawnPoint)
self.score = 0
...
end
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
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.
If you guys could help me find where the problem is that would be great.
Thanks.
Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeooow!!
Who is online
Users browsing this forum: Ahrefs [Bot] and 4 guests