If you looked at my code you would see that is not the same as what I have. Plus you can see mousepressed isn't being called at all so the hitboxes aren't the problem. What it looks like since I have font objects and not normal text: https://ibb.co/hUgi0fpedrosgali wrote: ↑Wed Oct 17, 2018 9:13 am Did you even try drawing the rectangles to the screen?
If you had you would have immediately seen your problem.
Mousepressed not working?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Mousepressed not working?
Re: Mousepressed not working?
Look I really appreciate that solution. I'll use it if all else fails. But I would really like to find out why love.mousepressed isn't being called at all if possible.KowalewskajA wrote: ↑Tue Oct 16, 2018 1:14 am Before I offer you a solution I would definately recommend you to read the documentation or try some tutorial .
Anyway here is a working solution(rectangles are just for visualing the hitboxes):Thats how it looked afterwards:Code: Select all
function love.load() menu_load() end function love.update(dt) local down = love.mouse.isDown(1) local mx = love.mouse.getX() local my = love.mouse.getY() menu_mousehandling(mx, my, down) end function love.draw() menu_draw() end function menu_load() menubuttons = { startButton = {hover = false, text = "Start", x = 200, y = 300, call = startgame}, exitButton = {hover = false, text = "Exit", x = 200, y = 500, call = exitgame}, optionsButton = {hover = false, text = "Options", x = 200, y = 400, call = openoptions} } redColor = {255,0,0,255} whtColor = {255,255,255,255} end function menu_draw() love.graphics.printf("KNIGHTLY", 200, 100, 400, "center") for i, v in pairs(menubuttons) do if v.hover == true then love.graphics.setColor(redColor) else love.graphics.setColor(whtColor) end love.graphics.printf(v.text, v.x, v.y, 400, "center") love.graphics.rectangle('line', v.x + 200 - 100, v.y - 20, 200, 40) love.graphics.setColor(whtColor) end end function menu_update(Somethinglikedt) end function menu_mousehandling(mx, my, down) for i, v in pairs(menubuttons) do if mx > v.x + 200 - 100 and mx < v.x + 200 + 100 and my > v.y - 20 and my < v.y + 20 then v.hover=true if down == true then v.call() end else v.hover=false end end end function startgame() print("startinggame") end function exitgame() print("quiting") end function openoptions() print("fetchingoptions") end
Hope that helped ya,
KowalewskajA
Re: Mousepressed not working?
Thanks for your help. Where do I start to analyse why my mousepressed event isn't working? I am pretty clueless at this point.
- zorg
- Party member
- Posts: 3469
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Mousepressed not working?
I'm skeptical about what you actually did here, or if you actually understood what pgimeno was explaining.xpali2 wrote: ↑Tue Oct 16, 2018 1:31 pmI had not actually done this, but putting this function in the main.lua - to my surprise - did not actually fix the issue. When I put a print statement in the function to see if a click was detected at all it doesn't print anything. In fact, it even doesn't print anything when I put the print function in love.mousepressed itself.xNick1 wrote: ↑Tue Oct 16, 2018 7:06 am Are you calling the menu_mousepressed function from main.lua?
Like:
Othewise how would it know it has to call it?Code: Select all
function love.mousepressed( x, y, button, istouch, presses ) menu_mousepressed(x, y, button, istouch, presses) end
If so, are you sure it isn't calling it?
Maybe the coordinates are wrong.
Try to print something in the function, like:
Code: Select all
function menu_mousepressed(x, y, button) print("I entered the menu mousepressed function") for i, v in pairs(menubuttons) do if x > v.x and x < v.x + 200 and y > v.y and y < v.y + 35 then v.call() end end end
Maybe just share a love file with your current code, that way we could find the issue faster, instead of resorting to guessing.
Me and my stuff True 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.
Re: Mousepressed not working?
You may have two mousepressed events.
You may be declaring it somewhere where it does not execute.
The print may be working but not being shown in the output for some reason.
Or many other possibilities that haven't occurred to me. As zorg notes, all we can do is guess, and I should add that it's frustrating.
One way to find out if it's being overwritten by another definition is to set a global immediately after declaring the love.mousepressed function:
Code: Select all
function love.mousepressed(...)
...
end
LoveMousepressed = love.mousepressed
Re: Mousepressed not working?
I did understand. And I changed it accordingly. Here is my main.lua file.zorg wrote: ↑Wed Oct 17, 2018 4:09 pmI'm skeptical about what you actually did here, or if you actually understood what pgimeno was explaining.xpali2 wrote: ↑Tue Oct 16, 2018 1:31 pmI had not actually done this, but putting this function in the main.lua - to my surprise - did not actually fix the issue. When I put a print statement in the function to see if a click was detected at all it doesn't print anything. In fact, it even doesn't print anything when I put the print function in love.mousepressed itself.xNick1 wrote: ↑Tue Oct 16, 2018 7:06 am Are you calling the menu_mousepressed function from main.lua?
Like:
Othewise how would it know it has to call it?Code: Select all
function love.mousepressed( x, y, button, istouch, presses ) menu_mousepressed(x, y, button, istouch, presses) end
If so, are you sure it isn't calling it?
Maybe the coordinates are wrong.
Try to print something in the function, like:
Code: Select all
function menu_mousepressed(x, y, button) print("I entered the menu mousepressed function") for i, v in pairs(menubuttons) do if x > v.x and x < v.x + 200 and y > v.y and y < v.y + 35 then v.call() end end end
Maybe just share a love file with your current code, that way we could find the issue faster, instead of resorting to guessing.
Code: Select all
love.graphics.setDefaultFilter("nearest", "nearest")
require("Icons&Extras/Menu/menu")
function love.load()
gamestate = "inMenu"
menu_load()
end
function love.draw()
if gamestate == "inMenu" then
menu_draw()
end
end
function love.update(dt)
if gamestate == "inMenu" then
menu_update(dt)
end
end
function love.mouspressed(x, y, button)
print("Mousepressed was called")
if gamestate == "inMenu" then
menu_mousepressed(x, y, button)
end
end
function love.mousemoved(x, y)
if gamestate == "inMenu" then
menu_mousemoved(x, y)
end
end
Re: Mousepressed not working?
I'll tell you it's just as frustrating on my end. If I am not giving you something you think you need to see to solve the issue then ask away, I am not an experienced coder so I can't guess what you need to hear. I have to say that I don't get what you mean with "two mousepressed events" if you could explain. I have checked the console many times by putting a print outside of the basic callbacks in main.lua that print to the console I am viewing: https://ibb.co/f6LEaf. I have tried "LoveMousepressed = love.mousepressed" but nothing changes, no errors or anything. Btw, mousemoved does work, so I reckon the mouse isn't the problem, meaning the mouse module is also not the issue.pgimeno wrote: ↑Wed Oct 17, 2018 4:37 pmYou may have two mousepressed events.
You may be declaring it somewhere where it does not execute.
The print may be working but not being shown in the output for some reason.
Or many other possibilities that haven't occurred to me. As zorg notes, all we can do is guess, and I should add that it's frustrating.
One way to find out if it's being overwritten by another definition is to set a global immediately after declaring the love.mousepressed function:and then in your love.draw, print both LoveMousepressed and love.mousepressed to see if they match.Code: Select all
function love.mousepressed(...) ... end LoveMousepressed = love.mousepressed
-
- Party member
- Posts: 107
- Joined: Wed Oct 15, 2014 5:00 pm
- Location: Yorkshire, England
Re: Mousepressed not working?
Here's a .love of the file you posted with a main.lua to make it work, if you click in the boxes I drew the function gets called. I don't know what else to tell you.
I got it to launch with a console (windows only) to show that the function is being called.
I copied the code you posted and wrote a main.lua, I had to get rid of the fonts as I needed to run the file to check.
I got it to launch with a console (windows only) to show that the function is being called.
I copied the code you posted and wrote a main.lua, I had to get rid of the fonts as I needed to run the file to check.
Code: Select all
if not wearTheseGlasses() then
chewing_on_trashcan = true
end
Re: Mousepressed not working?
This one does work for me as well. It's a different version than my love but that doesn't seem to pose an issue. I have just as much of an idea of why this works and mine doesn't as you do.pedrosgali wrote: ↑Wed Oct 17, 2018 6:18 pm Here's a .love of the file you posted with a main.lua to make it work, if you click in the boxes I drew the function gets called. I don't know what else to tell you.
menuhelp.love
I got it to launch with a console (windows only) to show that the function is being called.
I copied the code you posted and wrote a main.lua, I had to get rid of the fonts as I needed to run the file to check.
-
- Party member
- Posts: 107
- Joined: Wed Oct 15, 2014 5:00 pm
- Location: Yorkshire, England
Re: Mousepressed not working?
The main.lua file should look like this:
Well I'm sure there will be other things in there but that's the minimum you need to get your code working. Once you do your positioning is off You're drawing a box 400 wide with the text but checking a box 200 wide for clicks.
Code: Select all
local menu = require "menu"
function love.load()
menu_load()
end
function love.mousepressed(x, y, b)
menu_mousepressed(x, y, b)
end
function love.update(dt)
end
function love.draw()
menu_draw()
end
Code: Select all
if not wearTheseGlasses() then
chewing_on_trashcan = true
end
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot] and 9 guests