I’m trying to include a pure lua pathfinding library which works fine in lua, but inside defold it has build errors. Does defold use some breaking version of lua? I can’t figure out why these errors are happening.
This is the lua library I downloaded, and put into a jumper folder inside my main folder for the defold project, and then used require() in main.script to get the script to load, using this example script directly from the github.
This library is a pathfinding library. I know there’s already one made for defold but it’s not as good, for one thing the pathing in the defold one is robotic/overly simplistic, in this one the paths generated are ones humans would take which cost the same - because it understands more than one heuristic for tile cost.
-- Set up 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
-- Library setup
-- Calls the grid class
local Grid = require ("main.jumper.grid")
-- Calls the pathfinder class
local Pathfinder = require ("main.jumper.pathfinder")
-- Creates a grid object
local grid = Grid(map)
-- Creates a pathfinder object using Jump Point Search algorithm
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 = myFinder:getPath(startx, starty, endx, endy)
-- Pretty-printing the results
if path then
print(('Path found! Length: %.2f'):format(path:getLength()))
for node, count in path:nodes() do
print(('Step: %d - x: %d - y: %d'):format(count, node:getX(), node:getY()))
end
end