This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Joe3000's profile picture

Bios:367: [string "a"] :128: unfinished long string <--- what is this!?

Started by Joe3000, 26 May 2015 - 02:22 AM
Joe3000 #1
Posted 26 May 2015 - 04:22 AM
Ok, so I cread a program (named "a") to test A* pathing because I wanted to learn… I think I nearly completed it but when I ran it i got this random error. The thing is, I get the error on the very last line of code, which is how I'm testing to see if the algorithm actually worked. But the last line of code is a simple print() and i'm getting this "unfinished long string" error and I don't understand why. I'm going to include all of my code just in case it has something to do with the main part, but its the last line of code giving the error


local l,h = term.getSize()
local nodes = {}
local open = {}
local closed = {}
local targetX = 10;
local targetY = 10;
local foundPath = false
function createNode(x,y)
  node = {
    xpos = x;
    ypos = y;
    parent = null;
    hValue = 0;
    gValue = 0;
    fValue = 0;
   
    init = function(self)
	  self.hValue = (math.abs(targetX - self.xpos) + math.abs(targetY - self.ypos))
	  self.gValue = parent.gValue+10
	  self.fValue = self.gValue + self.hValue
    end;
   
    first = function(self)
	  fValue = 0
	  self.gValue = 0
	  if self.xpos - 1 > 0 and closed[self.xpos-1][self.ypos]==0 then
	    nodes[self.xpos-1][self.ypos].parent = nodes[self.xpos][self.ypos]
	    open[self.xpos-1][self.ypos] = 1
	    nodes[self.xpos-1][self.ypos]:init()
	  end
	  if self.xpos + 1 > 0 and closed[self.xpos+1][self.ypos]==0 then
	    nodes[self.xpos+1][self.ypos].parent = nodes[self.xpos][self.ypos]
	    open[self.xpos+1][self.ypos] = 1
	    nodes[[self.xpos+1][self.ypos]:init()
	  end
	  if self.ypos - 1 > 0 and closed[self.xpos][self.ypos -1]==0 then
	    nodes[self.xpos][self.ypos -1].parent = nodes[self.xpos][self.ypos]
	    open[self.xpos][self.ypos -1] = 1
	    nodes[self.xpos][self.ypos -1]:init()
	  end
	  if self.ypos + 1 > 0 and closed[self.xpos][self.ypos+1]==0 then
	    nodes[self.xpos][self.ypos+1].parent = nodes[self.xpos][self.ypos]
	    open[self.xpos][self.ypos+1] = 1
	    nodes[self.xpos][self.ypos+1]:init()
	  end
	  if self.xpos + 1 == targetX or self.xpos -1 == targetX then
	    if self.ypos + 1 == targetY or self.ypos -1 == targetY then
		  foundPath = true
	    end
	  end
    end;
   
  }
  return node
end
local function findPathBack()
end
local function checkNode(x,y)
  if nodes[x][y].xpos - 1 > 0 and closed[x-1][y]==0 then
	 nodes[x-1][y].parent = nodes[x][y]
	 open[x-1][y] = 1
	 nodes[x-1][y]:init()
  end
  if nodes[x][y].xpos + 1 <= l and closed[x+1][y] == 0 then
    nodes[x+1][y].parent = nodes[x][y]
    open[x+1][y] = 1
    nodes[x+1][y]:init()
  end
  if nodes[x][y].ypos - 1 > 0 and closed[x][y-1] == 0 then
    nodes[x][y-1].parent = nodes[x][y]
    open[x][y-1] = 1
    nodes[x][y-1]:init()
  end
  if nodes[x][y].ypos + 1 <= h and closed[x][y+1] == 0 then
    nodes[x][y+1].parent = nodes[x][y]
    open[x][y+1] = 1
    nodes[x][y+1]:init()
  end
  if nodes[x][y].xpos + 1 == targetX or nodes[x][y].xpos -1 == targetX then
    if nodes[x][y].ypos + 1 == targetY or nodes[x][y].ypos -1 == targetY then
	  foundPath = true
    end
  end
  closed[x][y] = 1
end

for x = 1, l do
  nodes[x] = {}
  open[x] = {}
  closed[x] = {}
  for y = 1, h do
    nodes[x][y] = createNode(x,y)
    if x ==1 and y == 1 then
	  nodes[x][y]:first()
    end
    open[x][y] = 0
    closed[x][y] = 0
  end
end
closed[1][1] = 1
while not foundPath do
  lowestF = 100
  lowestX = null
  lowestY = null
 
  for i,v in pairs(open) do
    for n,p in pairs(open[i]) do
	  if nodes[i][n].fValue < lowestF then
	   lowestF = nodes[i][n].fValue
	   lowestX = i
	   lowestY = n
	  end
    end
  end
  checkNode(lowestX, lowestY)
end
print("Path Found!")
valithor #2
Posted 26 May 2015 - 04:46 AM
Your problem is this line

nodes[[self.xpos+1][self.ypos]:init()
You accidently put two ['s, which is what lua uses to signify multi line strings. Because of this it expects two more ]'s to close the string hence your error, unfinished long string, or unfinished multiline string.
Edited on 26 May 2015 - 02:48 AM