Yonaba/Jumper

Invalid or unreachable location

bsherb53 opened this issue · 3 comments

Yonaba,

I currently have a grid displaying, and a player can touch a square and it would calculate a path from the center square in the map to the square that the player touched. The funny thing is, sometimes I have troubles with the assert on line ~340? (I changed mine for debugging). I get the "Invalid or unreachable at [endx][endy]" error, but it is not displaying the correct endy value.

For example, if I click on grid[3][10], it might be valid and everything works great. If I then click on grid [3][11], it says unreachable at 3,10. The weird part is that depending on what device I am emulating the rows and columns are different, i.e. iphone 4 doesn't work for row 7 and sg3 doesn't work on col 7,10 or 14.

It is really strange. I have a video here:
http://screencast.com/t/IRZZqfvl5a

and here are some screenshots:
http://screencast.com/t/79v3PLgih6HF
http://screencast.com/t/E4CZN5na9

I don't know if you have any insights: I have been struggling on this issue and can't seem to find any answers online.

Thank you, you have always been so helpful

Hi, @bsherb53
I believe the problem should be related to the tile coordinates you are dealing with in your getPath function. How do you actually convert screen coordinates (when touching on the screen) to tile/grid coordinates ?

Here is the shortened version of my touch listener:
numRows = 11 -- the number of rows to display
numCols = 17 -- the number of columns to display
numGridHeight = display.contentHeight / numRows -- this tells me the # of pixels in each tile's height
numGridWidth = display.contentWidth / numCols -- this tells me the # of pixels in each tile's width
moveToCol = ( event.x - ( event.x % numGridWidth ) + numGridWidth ) / numGridWidth
moveToRow = ( event.y - ( event.y % numGridHeight) + numGridHeight) / numGridHeight

and here is my getPath()

-- find the path from point A to point B
function getPath(goToCol, goToRow)
-- Creates a pathfinder object using Jump Point Search algorithm
-- Creates a grid object
local grid = Grid(map)

-- Creates a pathfinder object using Jump Point Search
local myFinder = Pathfinder(grid, 'JPS', walkable)
myFinder:setMode("ORTHOGONAL")

-- Calculates the path, and its length
   -- 8,6 is the coordinates of the center of the screen, it will always be these variables.
local path, length = myFinder:getPath(8,6, goToCol, goToRow)
if path then
    --print(('Path found! Length: %.2f'):format(length))
    for node, count in path:iter() do
        --updateGrid(node.x, node.y)
        --print(('Step: %d |x: %d| y: %d'):format(count, node.x, node.y))
        --hero.xList[count] = node:getX()
        --hero.yList[count] = node:getY()
    end
    startx = goToCol
    starty = goToRow
else
    --print("No Path")
end 
end

I do currently have all my files up to date in my repo

It is all in my main.lua file.

Thanks again for all your help

Ok. I did the old fashion thing... Put the program away, wait a couple weeks and come back. Sure enough it worked. I was not rounding each of my tiles in my 2D matrix to the nearest pixel. Once I did that. It fixed it right away.