Hello,
I’m trying to write a function for path finding.
--//node table is like this: --//{{y, x, cost, parent}, {y2, x2, cost2, parent2}} --//A function like this: function count(nodeTable) local y, x, cost, parent for i=1, #nodeTabledo y = nodeTable[i][1] --// ALWAYS error here if #nodeTable is not 1 when I try tail calls x = nodeTable[i][2] cost = nodeTable[i][3] parent = nodeTable[i][4] doSomething() --//checks things, removes checked nodes and insert new nodes into a new table for the next loop end if(#newNodeTable ~= 0) then return count(newNodeTable) --// tail call end end
However it will cause a error when the size of node table is not 1 at the line I marked
If I don’t use tail call, that line will pass just fine, but I need recursion t finish the path finder.
There must be something wrong.
Can someone help me?
Thanks!