Single mouse button an issue?

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
SquireTara
Prole
Posts: 2
Joined: Sat Jul 24, 2010 4:56 pm

Single mouse button an issue?

Post by SquireTara »

I have a mac book pro laptop with 1 mouse button. I've been playing around with taking keyboard and mouse input and have discovered that

Code: Select all

function love.mousepressed(x, y, button)
	text = "Mouse button is "..button
end
prints out "Mouse button is 1" as it should. But when I try to run the code in the tutorial (the code meant to only change the text when mouse button 1 is pressed), it never changes the text. Is this because I have a single button mouse?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Single mouse button an issue?

Post by Robin »

The thing is, that's not a 1 (one), but an l (el). (See http://love2d.org/wiki/MouseConstant)
Help us help you: attach a .love.
Freonce
Prole
Posts: 8
Joined: Tue Jul 27, 2010 6:26 pm

Re: Single mouse button an issue?

Post by Freonce »

But when I try to run the code in the tutorial (the code meant to only change the text when mouse button 1 is pressed)
Are you talking about the using input tutorial? I gave it a spin and it worked ok...thought I am using a PC so I can't say if its due to the one button or not.

Code: Select all

function love.load()
    love.graphics.setFont(12)
    text = "Nothing yet"
end

function love.update(dt)
   if love.keyboard.isDown( " " ) then
      text = "SPACE is being pressed!"
   end
   
   if love.mouse.isDown("r") then
   text = "Mouse button right is pressed"
   end

   mouse_x = love.mouse.getX()
   mouse_y = love.mouse.getY()
   
end

function love.draw()
      love.graphics.print( text, 330, 300 )
	  love.graphics.print( "Mouse X: ".. mouse_x .. " Mouse Y: " .. mouse_y, 10, 20 )
end

function love.keypressed( key )
   if key == "return" then
      text = "RETURN is being pressed!"
   end
   
   if key == 'h' then
		if love.mouse.isVisible() then
		   love.mouse.setVisible(false)
        else
           love.mouse.setVisible(true)
		end
   end
   
end

function love.keyreleased( key )
   if key == "return" then
      text = "RETURN has been released!"
   end
end

if love.mouse.isDown("r") then
   text = "Mouse button right is pressed"
end

function love.mousepressed(x, y, button)
   if button == 'l' then
      text = "Mouse button left is pressed at X:"..x.." Y: "..y
   end
end

function love.mousereleased(x, y, button)
   if button == 'l' then
      text = "Mouse button left is released"
   end
end
That's what I got out of it. Maybe check it against what you have and see if like Robin said you have any 1's(number) where there should be l's (letter). I'm still new to all this lua madness so take anything I say with a grain of salt. :P
SquireTara
Prole
Posts: 2
Joined: Sat Jul 24, 2010 4:56 pm

Re: Single mouse button an issue?

Post by SquireTara »

I changed all the 1s in my code to Ls and now it works. Thanks a bunch!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 6 guests