Using mouse input, left mouse button not doing anything??

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
PixelPixel
Prole
Posts: 3
Joined: Wed Jun 20, 2018 7:46 am

Using mouse input, left mouse button not doing anything??

Post by PixelPixel »

This works nicely for the right mouse button

Code: Select all

 if love.mouse.isDown(1) then
   text = "Right mouse button has been pressed"
end
Left mouse button however causes troubles, I tried other index numbers too, still nilch, nada & zero reaction from love
here is the code...

Code: Select all

 if love.mouse.isDown(2) then
   text = "Left mouse button has been pressed"
end
What to do?
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: Using mouse input, left mouse button not doing anything??

Post by KayleMaster »

Where did you put that code? Can you share your project? It should work, but I don't know the context.
EDIT: isn't 1 left mouse button and 2 right mouse button?
PixelPixel
Prole
Posts: 3
Joined: Wed Jun 20, 2018 7:46 am

Re: Using mouse input, left mouse button not doing anything??

Post by PixelPixel »

Sorry for not giving much context or code, I put the code in the update function;

Code: Select all

function love.update(dt)

 if love.mouse.isDown(1) then
   text = "Right mouse button has been pressed"
end

 if love.mouse.isDown(2) then
   text = "Left mouse button has been pressed"
end

end
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Using mouse input, left mouse button not doing anything??

Post by grump »

What do you expect that code to do?
KayleMaster
Party member
Posts: 234
Joined: Mon Aug 29, 2016 8:51 am

Re: Using mouse input, left mouse button not doing anything??

Post by KayleMaster »

I guess he has text in a love.graphics.print in love.draw.
Anyways, you've got them wrong, they're the other way around. 1 is left mouse, 2 is right mouse, 3 is middle mouse button.
PixelPixel
Prole
Posts: 3
Joined: Wed Jun 20, 2018 7:46 am

Re: Using mouse input, left mouse button not doing anything??

Post by PixelPixel »

I've got it working now, here is the full code

I have no idea why it wasn't working properly before but now it is..

Code: Select all

local text
 
function love.load()
   love.graphics.setNewFont(12)
   text = "Nothing yet"
end
 
function love.update(dt)

  if love.mouse.isDown( '1' ) then 
    text = "Left mouse button has been pressed"
  end

    if love.mouse.isDown( '2' ) then 
    text = "Right mouse button has been pressed"
  end

end
 
function love.draw()
   love.graphics.print( text, 330, 300 )
end
Post Reply

Who is online

Users browsing this forum: No registered users and 49 guests