Page 1 of 1

Mouse problems

Posted: Sun Dec 21, 2014 11:54 pm
by Wittloc
This function here;

Code: Select all

function love.update(dt)
	if love.mouse.getY() >= 65 and love.mouse.getY() <= 65 + 33 then
		selectedbutton = 1
		if love.mouse.isDown("l") and mon == true then
			mon = false
			gameplay = 2
			wait(2)
			gameplay = 1
		end
	end
end
Doesn't do anything.
mon is a value set to True somewhere else in the script.

Re: Mouse problems

Posted: Mon Dec 22, 2014 1:31 am
by szensk
What does wait(2) do? I suspect it does something that it shouldn't (like sleep for 2 seconds?).

It works perfectly fine in my test. Wait is called once and only once if you click within a y range of 65 to 98.

Code: Select all

local mon = true
local selectedbutton = nil
local gameplay = 0

local function wait(n)
    love.window.setTitle(tostring(love.timer.getTime()))
end

function love.draw()
    local r,g,b,a = love.graphics.getColor()
    local newa = mon and 170 or 255
    love.graphics.setColor(218, 0, 0, newa)
    love.graphics.print(("x: %.2f y: %.2f Gameplay: %d"):format(love.mouse.getX(),
                        love.mouse.getY(), gameplay), 2, 2)
    love.graphics.rectangle("fill", 0, 65, 800, 33)
    love.graphics.setColor(r,g,b,a)
end

function love.update(dt)
    if love.mouse.getY() >= 65 and love.mouse.getY() <= 65 + 33 then
        selectedbutton = 1
        if love.mouse.isDown("l") and mon == true then
            mon = false
            gameplay = 2
            wait(2)
            gameplay = 1
        end
    end
end