I’m making a Roguelike game and I am currently working on the Dungeon Generation using an open source Dungeon Generation page I found on GitHub. So far it’s working fine, but I’ve encountered an error that seems very simple, I just don’t know how to go about fixing it. Here’s a screenshot:
Here is the function that is causing the error:
function Level:getRoomTree()
if #self.rooms < 1 then error("Can't generate room tree, no rooms exists") end
local root, lastLeaf = prims(table.clone(self.rooms)) -- This is the line causing the error
self.rootRoom = root
self.endRoom = lastLeaf
return root
end
I decided I’d print out the value that the prims
function is receiving and it returned nil,
Here is the code for the prims
function:
function HelpFunctions:prims(unvisited)
print(unvisited)
local len = #unvisited
local root = remove(unvisited, 1)
if #unvisited==0 then return root, root end
local visited={}
insert(visited, root)
local v0
local endIndex
repeat
local dist = 1e309 -- ~inf
for i = 1, #visited do
for j = 1, #unvisited do
if (unvisited[j]:distanceTo(visited[i]) < dist) then
dist = unvisited[j]:distanceTo(visited[i])
v0 = visited[i]
endIndex = j
end
end
end
local v1 = remove(unvisited, endIndex)
v0:addNeighbour(v1)
insert(visited, v1)
until #visited == len
return visited[1], visited[#visited]
end
I’m just a bit confused, help is appreciated! Thanks!