Page 1 of 1

Hump Gamestate Freezing on switch function

Posted: Sat Mar 01, 2014 10:44 pm
by Oprogrammer
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.

Re: Hump Gamestate Freezing on switch function

Posted: Sat Mar 01, 2014 11:10 pm
by Rehnrald
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

Re: Hump Gamestate Freezing on switch function

Posted: Sun Mar 02, 2014 11:43 pm
by Oprogrammer
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 ..

Re: Hump Gamestate Freezing on switch function

Posted: Mon Mar 03, 2014 1:02 am
by MadByte
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 :[ ).

Re: Hump Gamestate Freezing on switch function

Posted: Mon Mar 03, 2014 1:18 am
by Helvecta
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 :nyu:

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 
		Gamestate.switch(Gamestate.Menu)
		
		
	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. :monocle:

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! :x

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

Re: Hump Gamestate Freezing on switch function

Posted: Mon Mar 03, 2014 9:24 am
by vrld
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 'Menu'
require 'Game'
require 'Splashscreen'
Timer = require 'hump.timer'

function love.load()
    Gamestate.registerEvents()
    Gamestate.switch(Gamestate.Splashscreen)
    Timer.add(3, function() Gamestate.switch(Gamestate.Menu) end)
end

function love.update(dt)
    Timer.update(dt)
end

Re: Hump Gamestate Freezing on switch function

Posted: Mon Mar 03, 2014 12:20 pm
by Oprogrammer
Thank you very much guys !! I will take all your feedback and apply it to the game.