Question about "require" works (DEF-2116) (SOLVED)

Thats my code:
local Finders = {
[‘ASTAR’] = require ‘path.jumper.search.astar’,
[‘DIJKSTRA’] = require (‘path.jumper.search.dijkstra’),
[‘THETASTAR’] = require (‘path.jumper.search.thetastar’),
[‘BFS’] = require (‘path.jumper.search.bfs’),
[‘DFS’] = require (‘path.jumper.search.dfs’),
[‘JPS’] = require (‘path.jumper.search.jps’)
}

Defold send me an error: “module ‘path.jumper.search.astar’ not found”, why?

Where in the project structure do the file “astar.lua” reside?

We discussed this on Slack earlier and I asked to have the question posted here as well. The thing with require() calls is that we search all script files for require calls when building and make sure to include all required files with the rest of the assets of the game. This is why it is not possible to create the require path at runtime for instance:

require("this." .. "will." .. "not." .. "work")
local foobar = "this.will.not.work.either"
require(foobar)

The above is completely valid Lua code, but due to how our build pipeline works we will not be able to pick up those files and include them in the build.

Now, the code posted by @ars3577 should be ok, but apparently there’s an issue with the detection of those require calls. We’ve had a similar issue in the passed where it was not possible to have a comment after a require call.

Created ticket: DEF-2116

I see. As a workaround, can you manually add the folder “path” to the dependencies in the project settings?

A workaround would look like this:

local astar = require 'path.jumper.search.astar',
local dijkstra = require ('path.jumper.search.dijkstra'),
local thetastar = require ('path.jumper.search.thetastar'),
local bfs = require ('path.jumper.search.bfs'),
local dfs = require ('path.jumper.search.dfs'),
local jps = require ('path.jumper.search.jps')

local Finders = {
  ['ASTAR']     = astar,
  ['DIJKSTRA']  = dijkstra,
  ['THETASTAR'] = thetastar,
  ['BFS']       = bfs,
  ['DFS']       = dfs,
  ['JPS']       = jps,
}
1 Like

Yes, of course. Adding the path to “custom_resources” does not work since you get a build error with those requires.

Solved in Defold 1.2.90

2 Likes