[SOLVED] Pathfinding > A* + Jumper = Can't set it up :(

Hi guys

I’m currently struggling with the very very very basics of a A*-based pathfinder (Jumper). Pretty sure I’ll be able to use it in my prototype once it’s set up, but for now I can’t even make the simple example work…

Note: I already used this pathfinder -2-3 years ago- with Love2D for an “advanced wars” prototype, and I don’t remember experiencing issues when setting it up :thinking:

Looks like the “length” is not calculated (nil value - while the path itself seems to be found), but I’m not skilled enough to understand why :see_no_evil: . . . (but it also may be something silly/obvious…)
image
:arrow_down:
image

Just in case, I shared a super ultra minimal version of my test project (nothing except a simple script) so someone can take a quick look at it:

:pray:

1 Like

I think you need to share some code showing how you are using the Jumper library. And maybe you can set a breakpoint and step through the code using the debugger?

Also, I think @Alex_8BitSkull is using Jumper in Fates of Ort.

1 Like

@britzl
I copy-pasted the super simple example provided with Jumper (cf Jumper’s repo + my minimal project).

It was so straightforward that I may have missed something hyper obvious :thinking:

Here is the content of the script:

---========================---
---== LUA MODULE IMPORTS ==---
---========================---
local Grid = require ("jumper.grid") -- The grid class
local Pathfinder = require ("jumper.pathfinder") -- The pathfinder class

---========================---
---========================---


-- Usage Example
-- First, set a collision map
local map = {
	{0,1,0,1,0},
	{0,1,0,1,0},
	{0,1,1,1,0},
	{0,0,0,0,0},
}
-- Value for walkable tiles
local walkable = 0

-- Creates a grid object
local grid = Grid(map)
-- Creates a pathfinder object using Jump Point Search
local myFinder = Pathfinder(grid, 'JPS', walkable)

-- Define start and goal locations coordinates
local startx, starty = 1,1
local endx, endy = 5,1

-- Calculates the path, and its length
local path, length = myFinder:getPath(startx, starty, endx, endy)


function init(self)
	
	if path then
		print(('Path found! Length: %.2f'):format(length))
		for node, count in path:iter() do
			print(('Step: %d - x: %d - y: %d'):format(count, node.x, node.y))
		end
	else
		print("No path!")
	end
	
end

I don’t know what happens inside myFinder:getPath but it seems like it returns a path but no length. I don’t know why that is. Debugging the code using the debugger might help.

Looking at the path finder code, it doesn’t return a length?

@britzl
@Mathias_Westerdahl

Note that I also get an error if with the second print (after marking the “length” line as a comment)

image

The library is supposed to work fine, I’ve used it in the past with a Love2D project, so… I’m wondering what I did wrong… if there is a Defold-specific thing I’ve missed. Or is this is a Defold-specific issue? I don’t know

Maybe @Alex_8BitSkull will be able to tell :slight_smile: (if he has used Jumper in a Defold project)

You didn’t post the error, so it’s hard to guess

image
:arrow_down:
image

And, what if you pprint “node”, what does it actually contain?

image
:arrow_down:
image




PS: there was a repo in my first message: (if you think it can help), with a super minimal version

Try “pprint”:

pprint(“node”, node)

1 Like
DEBUG:SCRIPT: nil,
{ --[[000001B0ADCB0010]]
  _opened = true,
  _h = 0,
  _y = 1,
  _x = 1,
  _g = 0,
  _clearance = { } --[[000001B0ADCB0060]],
  _f = 0,
  _closed = true
}
DEBUG:SCRIPT: nil,
{ --[[000001B0ADCB0C30]]
  _opened = true,
  _h = 6,
  _g = 2,
  _parent = { --[[000001B0ADCB0010]]
    _opened = true,
    _h = 0,
    _y = 1,
    _x = 1,
    _g = 0,
    _clearance = { } --[[000001B0ADCB0060]],
    _f = 0,
    _closed = true
  },
  _y = 3,
  _x = 1,
  _clearance = { } --[[000001B0ADCB0C80]],
  _f = 8,
  _closed = true
}
DEBUG:SCRIPT: nil,
{ --[[000001B0ADCB1370]]
  _opened = true,
  _h = 6,
  _g = 3.4142135623731,
  _parent = { --[[000001B0ADCB0C30]]
    _opened = true,
    _h = 6,
    _g = 2,
    _parent = { --[[000001B0ADCB0010]]
      _opened = true,
      _h = 0,
      _y = 1,
      _x = 1,
      _g = 0,
      _clearance = { } --[[000001B0ADCB0060]],
      _f = 0,
      _closed = true
    },
    _y = 3,
    _x = 1,
    _clearance = { } --[[000001B0ADCB0C80]],
    _f = 8,
    _closed = true
  },
  _y = 4,
  _x = 2,
  _clearance = { } --[[000001B0ADCB13C0]],
  _f = 9.4142135623731,
  _closed = true
}
DEBUG:SCRIPT: nil,
{ --[[000001B0ADCB1590]]
  _opened = true,
  _h = 4,
  _g = 5.4142135623731,
  _parent = { --[[000001B0ADCB1370]]
    _opened = true,
    _h = 6,
    _g = 3.4142135623731,
    _parent = { --[[000001B0ADCB0C30]]
      _opened = true,
      _h = 6,
      _g = 2,
      _parent = { --[[000001B0ADCB0010]]
        _opened = true,
        _h = 0,
        _y = 1,
        _x = 1,
        _g = 0,
        _clearance = { } --[[000001B0ADCB0060]],
        _f = 0,
        _closed = true
      },
      _y = 3,
      _x = 1,
      _clearance = { } --[[000001B0ADCB0C80]],
      _f = 8,
      _closed = true
    },
    _y = 4,
    _x = 2,
    _clearance = { } --[[000001B0ADCB13C0]],
    _f = 9.4142135623731,
    _closed = true
  },
  _y = 4,
  _x = 4,
  _clearance = { } --[[000001B0ADCB15E0]],
  _f = 9.4142135623731,
  _closed = true
}
DEBUG:SCRIPT: nil,
{ --[[000001B0ADCB10B0]]
  _opened = true,
  _h = 2,
  _g = 6.8284271247462,
  _parent = { --[[000001B0ADCB1590]]
    _opened = true,
    _h = 4,
    _g = 5.4142135623731,
    _parent = { --[[000001B0ADCB1370]]
      _opened = true,
      _h = 6,
      _g = 3.4142135623731,
      _parent = { --[[000001B0ADCB0C30]]
        _opened = true,
        _h = 6,
        _g = 2,
        _parent = { --[[000001B0ADCB0010]]
          _opened = true,
          _h = 0,
          _y = 1,
          _x = 1,
          _g = 0,
          _clearance = { } --[[000001B0ADCB0060]],
          _f = 0,
          _closed = true
        },
        _y = 3,
        _x = 1,
        _clearance = { } --[[000001B0ADCB0C80]],
        _f = 8,
        _closed = true
      },
      _y = 4,
      _x = 2,
      _clearance = { } --[[000001B0ADCB13C0]],
      _f = 9.4142135623731,
      _closed = true
    },
    _y = 4,
    _x = 4,
    _clearance = { } --[[000001B0ADCB15E0]],
    _f = 9.4142135623731,
    _closed = true
  },
  _y = 3,
  _x = 5,
  _clearance = { } --[[000001B0ADCB1100]],
  _f = 8.8284271247462,
  _closed = true
}
DEBUG:SCRIPT: nil,
{ --[[000001B0ADCB0490]]
  _opened = true,
  _h = 0,
  _g = 8.8284271247462,
  _parent = { --[[000001B0ADCB10B0]]
    _opened = true,
    _h = 2,
    _g = 6.8284271247462,
    _parent = { --[[000001B0ADCB1590]]
      _opened = true,
      _h = 4,
      _g = 5.4142135623731,
      _parent = { --[[000001B0ADCB1370]]
        _opened = true,
        _h = 6,
        _g = 3.4142135623731,
        _parent = { --[[000001B0ADCB0C30]]
          _opened = true,
          _h = 6,
          _g = 2,
          _parent = { --[[000001B0ADCB0010]]
            _opened = true,
            _h = 0,
            _y = 1,
            _x = 1,
            _g = 0,
            _clearance = { } --[[000001B0ADCB0060]],
            _f = 0,
            _closed = true
          },
          _y = 3,
          _x = 1,
          _clearance = { } --[[000001B0ADCB0C80]],
          _f = 8,
          _closed = true
        },
        _y = 4,
        _x = 2,
        _clearance = { } --[[000001B0ADCB13C0]],
        _f = 9.4142135623731,
        _closed = true
      },
      _y = 4,
      _x = 4,
      _clearance = { } --[[000001B0ADCB15E0]],
      _f = 9.4142135623731,
      _closed = true
    },
    _y = 3,
    _x = 5,
    _clearance = { } --[[000001B0ADCB1100]],
    _f = 8.8284271247462,
    _closed = true
  },
  _y = 1,
  _x = 5,
  _clearance = { } --[[000001B0ADCB04E0]],
  _f = 8.8284271247462,
  _closed = true
}

Yeah, so you see that the info is there ("_x" and “_y”), so I guess since it’s an OOP interface with classes etc, there should be a way to access the info from the nodes?

EDIT: A quick look in their repo shows this:

assert_equal(node:getX(), 5)
assert_equal(node:getY(), 6)

So I guess you should use node:getX()etc

4 Likes

Wow thank you, it works fine now!

I’m ready to add creatures in my dungeon :slight_smile:

3 Likes