Strange issue - my function always thinks it is selecting something when im not
Posted: Tue Aug 29, 2017 11:03 am
I am programming something that uses a basic click and place blueprints for a wall. You click in an area and it creates a "wall" were you click, restricted to a tile grid. Cool that works fine, now I want to make it so if you right click on a wall BP it goes away. Seems simple enough right? Should be but I have a strange problem.
Here is my mousepressed function:
Here is the checkWallBP function:
two problems: for whatever reason no matter where I click it returns true. Regardless of there being a wall BP there it says there is. it accurately can tell me which wall it is, sorta. If I click where there isnt a wall it tells me the "wall" is wall number: (total walls + 1) no idea why. Also, it does say that there is a wall there when I click on a wall, but it doesnt remove it.
Walls are drawn like this:
any ideas folks?
Here is my mousepressed function:
Code: Select all
function love.mousepressed(x, y, button)
placeWallBP(x, y) -- draw walls
if button == 2 then -- if you right clicked
wallIs, wallWhich = checkWallBP(x, y) -- check if there is a wall BP in the grid section you clicked
if wallIs == 1 then -- if there is a wall, remove that wall from the arry
table.remove(wallbpX, wallWhich)
table.remove(wallbpY, wallWhich)
end
end
end
Code: Select all
function checkWallBP(x, y)
for i = 1, #wallbpX do -- check through each wall in the table for how many walls there are
if coordtoGrid(wallbpX[i]) == coordtoGrid(x) and coordtoGrid(wallbpY[i]) == coordtoGrid(y) then -- if there is a wall on the X spot and a wall on the Y spot, return true and where the wall is in the array
return 1, i
end
end
return 0
end
Walls are drawn like this:
Code: Select all
function drawWallBP()
for i = 1, #wallbpX do
love.graphics.draw(wallbpImg, wallbpX[i], wallbpY[i])
end
end
any ideas folks?