## Hump Gamestate Freezing on switch function

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Oprogrammer
Prole
Posts: 9
Joined: Sat Mar 01, 2014 10:37 pm

### Hump Gamestate Freezing on switch function

Hello

I am having an issue on switching gamestates using hump. I can use the Gamestate.switch function when going from the splash screen to the main menu , but when i use the Gamestate.switch function to go from the main menu into the game it self nothing happens, it remains on the main menu but i can still use the quit feature.

any idea's on what the problem is ?

PS: i have tried to use the Gamestate.push function instead of switch but there was no change. Also if i disable the splash screen and make the main menu load up , i can then switch Gamestates and get into the game it self.

Rehnrald
Prole
Posts: 29
Joined: Fri Jul 19, 2013 6:11 am

### Re: Hump Gamestate Freezing on switch function

Give us a .LOVE file to dissect and help you out. Here's a tutorial on how to do it if you don't already know, scroll down a bit to "Create a .love-file" and follow the instructions.

https://www.love2d.org/wiki/Game_Distribution

Oprogrammer
Prole
Posts: 9
Joined: Sat Mar 01, 2014 10:37 pm

### Re: Hump Gamestate Freezing on switch function

Sorry for the late reply , i have been trying to create a .love file , 5 hours later i have managed to do it , although .... when i try open to .love file myself i only get a black screen , but hopefully for you it should load the menu and game up ..
Attachments
platformer.love

Party member
Posts: 509
Joined: Fri May 03, 2013 6:42 pm
Location: Germany

### Re: Hump Gamestate Freezing on switch function

Basically the problem with your *.love file is that you made the first letter uppercase, it had to be "main.lua" not "Main.lua". That causes the black screen when starting from the file.

For the problem with the switch from menu to game :
I guess the problem is that the conditions ( if x> 871 and x< 1172 and y> 99 and y< 150 then ) aren't given. I tested to switch with press return ..

Code: Select all

-- Menu.lua
function state:keypressed(key)
if key == "return" then Gamestate.switch(Gamestate.Game) end
end

...and it worked ( there is a error with a tile inside your game and there are a couple more problems with your code btw. but I'm to lazy to list them here, sry :[ ).

Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

### Re: Hump Gamestate Freezing on switch function

The reason the .love file is funky is because Main.lua is capitalized in the zip file, which makes it black out when you try to run it, so I renamed the file so that the "M" is not capitalized

Anywho, the game itself is.. odd. No offense, but it's very rough. Moreso, I don't use (a lot of) external libraries so I couldn't tell you exactly why this problem is happening, but I do have a solution! It looks like the problem is coming specifically from

Code: Select all

	if timer < 0 then

end
If you change "timer < 0" to "timer > 0", state changing should work. Sorry I can't explain exactly why this is happening, my guess is that the gamestate is switched before HUMP is allowed to do its thing (since the game state changes on the first available frame).

I also made it so that you can see the button in question (I couldn't see any buttons being on the menu making it even more difficult to work with), so if you check it out you will notice some things have been changed. No worries though - the thing you needed help with is fixed.. although the game crashes immediately when you go to the "game" state.

On a side note now I have to upload this file outside of the forums since it's now somehow 14mb - larger than the max file upload limit -somehow. How did you upload this originally?! Did you.. compress the .zip? Shameful!

RRG. Uploading stuff online is so difficult, I just compressed the awesome Ocarina of Time music to fit to 10mb
Attachments
platformer.love

vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

### Re: Hump Gamestate Freezing on switch function

The actual problem is that you call Gamestate.switch() in love.update(). As the documentation states:
hump wrote:function registerEvents(callbacks)

Overwrite love callbacks to call Gamestate.update(), Gamestate.draw(), etc. automatically. love callbacks (e.g. love.update()) are still invoked.
In consequence, this means that you switch to the menu state on every frame. If you want to switch three seconds after the game is loaded, you can for example use hump.timer:

Code: Select all

Gamestate = require 'hump.gamestate'
require 'Game'
require 'Splashscreen'
Timer = require 'hump.timer'

Gamestate.registerEvents()
Gamestate.switch(Gamestate.Splashscreen)
end

function love.update(dt)
Timer.update(dt)
end
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine

Oprogrammer
Prole
Posts: 9
Joined: Sat Mar 01, 2014 10:37 pm

### Re: Hump Gamestate Freezing on switch function

Thank you very much guys !! I will take all your feedback and apply it to the game.

### Who is online

Users browsing this forum: Google [Bot] and 34 guests