0
votes

I have printed text that says "Yes". and I have to buttons in the shape of arrow. I am trying to get it so that if I click the left arrow it say "No" and if I click the right arrow is says "Yes".

fsdefault = "Yes"
fs = love.graphics.print(fsdefault, 440, 160)
love.graphics.draw(larrow, 425, 163)
love.graphics.draw(rarrow, 470, 163)

function love.update(dt)
function love.mousepressed( x, y)
    if x > 424 and x < 435 and y > 161 and y < 172 then 
        fsdefault = "No"
    end

    if x > 275 and x < 320 and y > 305 and y < 325 then 
        fsdefault = "Yes"
    end
end
end
1
x > 424 and x < 335. Chose an x. Would it ever satisfy both of the conditions? - hjpotter92
Sorry. it was meant to be 435. original post has been edited - Ross

1 Answers

1
votes

How about something like:

local fsdefault = ""
function love.mousepressed( x, y)
    if x > 424 and x < 435 and y > 161 and y < 172 then 
        fsdefault = "No"
    end

    if x > 275 and x < 320 and y > 305 and y < 325 then 
        fsdefault = "Yes"
    end
end

function love.draw()
    love.graphics.print(fsdefault, 440, 160)
    love.graphics.draw(larrow, 425, 163)
    love.graphics.draw(rarrow, 470, 163)
end

Note that for clarity, you should only perform screen drawing operations inside love.draw.

Also, try to avoid declaring functions inside love.update. That code snippet will make love redefine love.mousepressed every single frame of your game!