Switching gamestates with 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
CaptainSwordsman
Prole
Posts: 2
Joined: Wed Dec 23, 2015 4:30 am

Switching gamestates with HUMP

Post by CaptainSwordsman »

Hello. This is my first forum post, so please be gentle. For the first time I've run into a problem that I can't solve via Google and the Wiki. I'm trying to proof-of-concept a simple main menu using HUMP gamestates. I can switch from the main menu to the placeholder screen for my "new game" introduction just fine. However,when I click the mouse button on the "intro" state screen, it fails to return me back to the menu state properly. Everything else works fine, I'm just stuck trying to return to the main menu state and have it display and be interacted with properly.

Code: Select all

Gamestate = require "hump.gamestate"
local menu = {}
local game = {}
local intro = {}

function menu:init()
	bgImg = love.graphics.newImage('assets/gfx/mmbg.png')
	menuOp = love.graphics.newImage('assets/gfx/options_menu.png')
end

function menu:enter()
	menu:update()
end

function menu:update()
	
end

function menu:draw()
	love.graphics.draw(bgImg, 0, 0)
	love.graphics.draw(menuOp, 256, 240)
	
	if continuePressed == true then
		love.graphics.print('continuePressed', 10, 10)
	elseif optionsPressed == true then
		love.graphics.print('optionsPressed', 10, 10)
	end
	
end

function menu:mousepressed(x, y, button)
	if button == 'l' then
		if x > 256 and x < 384 and y > 240 and y < 288 then
			return Gamestate.switch(intro)
		elseif x > 256 and x < 384 and y > 298 and y < 346 then
			continuePressed = true
		elseif x > 256 and x < 384 and y > 356 and y < 404 then
			optionsPressed = true
		end
	end
	intro:update()
end

function menu:mousereleased(x, y, button)
	if button == 'l' then
		continuePressed = false
		optionsPressed = false
	end
end

function intro:init()
	introImg = love.graphics.newImage('assets/gfx/newGameScreen.png')
	backButton = love.graphics.newImage('assets/gfx/backButton.png')
end

function intro:enter()
	intro:update()
end

function intro:update()

end

--This function will of course be replaced when the actual intro sequence is coded
function intro:draw()
	love.graphics.draw(introImg, 0, 0)
	love.graphics.draw(backButton, 256, 240)
end

--This function will similarly be deleted
function intro:mousepressed(x, y, button)
	if button == '1' then
		return Gamestate.switch(menu)
	end
end

function game:update(dt)
	--
end

function love.load()
	Gamestate.registerEvents()
    Gamestate.switch(menu)
end
If anyone can spoonfeed me on how to properly use HUMP gamestates, I'll be very thankful. If not, well I'll try moving on to something else like Polygamy or Stateful. Thanks in advance guys!

LÖVE,
CaptainSwordsman
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Switching gamestates with HUMP

Post by bartbes »

In your intro:mousepressed function you're comparing the mouse button to "1", or the string representation of the number one, so Gamestate.switch is never called.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Switching gamestates with HUMP

Post by zorg »

bartbes wrote:In your intro:mousepressed function you're comparing the mouse button to "1", or the string representation of the number one, so Gamestate.switch is never called.
A bit of clarification, with löve 0.9.x, you need to use mouseconstants, like "l" (lowercase L) like you do in menu:mousepressed, but with 0.10.0 that had just been released, you need to use integers (positive whole numbers)

I'd suggest deciding on one of the versions; personally i'd suggest 0.10 since i see no harm in using the latest stable version (unless you have lots of code to rewrite) and stick to that, in which case, you'll need to edit the lowercase L in menu:mousepressed to be the number one instead. (you need to edit intro:mousepressed as well, since that's a string representation of 1, not the number itself, so "1" -> 1)

Hope i've been clear enough. :3
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
CaptainSwordsman
Prole
Posts: 2
Joined: Wed Dec 23, 2015 4:30 am

Re: Switching gamestates with HUMP

Post by CaptainSwordsman »

zorg wrote:
bartbes wrote:In your intro:mousepressed function you're comparing the mouse button to "1", or the string representation of the number one, so Gamestate.switch is never called.
A bit of clarification, with löve 0.9.x, you need to use mouseconstants, like "l" (lowercase L) like you do in menu:mousepressed, but with 0.10.0 that had just been released, you need to use integers (positive whole numbers)

I'd suggest deciding on one of the versions; personally i'd suggest 0.10 since i see no harm in using the latest stable version (unless you have lots of code to rewrite) and stick to that, in which case, you'll need to edit the lowercase L in menu:mousepressed to be the number one instead. (you need to edit intro:mousepressed as well, since that's a string representation of 1, not the number itself, so "1" -> 1)

Hope i've been clear enough. :3
bartbes wrote:In your intro:mousepressed function you're comparing the mouse button to "1", or the string representation of the number one, so Gamestate.switch is never called.
Wow GG I didn't even realize I was using lowercase L in one function and a number one in the other. I need to switch text editors. Thanks a lot!
Post Reply

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 6 guests