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

unexpected symbol, attempt to index ? (a nil value)

Started by jakeb89, 07 June 2012 - 02:12 AM
jakeb89 #1
Posted 07 June 2012 - 04:12 AM
I'm getting the following error: (copied exactly from turtle)

disk> test
bios:206: [string "miner"]:89:
unexpected symbol
test:3: attempt to index ? (a nil value)
disk>

Here is my code:

miner

[spoiler]function mineForward1()<br>&amp;nbsp;&amp;nbsp;while(turtle.forward()==false) do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;turtle.dig()<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sleep(0.3)<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;return true<br>end<br>function mineForward(n)<br>&amp;nbsp;&amp;nbsp;local i = 0<br>&amp;nbsp;&amp;nbsp;while(i&amp;lt;n) do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mineForward1()<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i = i + 1<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;return true<br>end<br>function mineUp1()<br>&amp;nbsp;&amp;nbsp;while(turtle.up()==false) do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;turtle.digUp()<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sleep(0.3)<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;return true<br>end<br>function mineUp(n)<br>&amp;nbsp;&amp;nbsp;local i = 0<br>&amp;nbsp;&amp;nbsp;while(i&amp;lt;n) do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mineUp1()<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i = i + 1<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;return true<br>end<br>function mineDown1()<br>&amp;nbsp;&amp;nbsp;while(turtle.down()==false) do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;turtle.digDown()<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sleep(0.3)<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;return true<br>end<br>function mineDown(n)<br>&amp;nbsp;&amp;nbsp;local i = 0<br>&amp;nbsp;&amp;nbsp;while(i&amp;lt;n) do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mineDown1()<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i = i + 1<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;return true<br>end<br>function backUp(n)<br>&amp;nbsp;&amp;nbsp;local i = 0<br>&amp;nbsp;&amp;nbsp;while(i&amp;lt;n) do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;while(turtle.back()==false) do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sleep(0.1)<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;i = i + 1<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;return true<br>end<br>function turnAround()<br>&amp;nbsp;&amp;nbsp;turtle.turnLeft()<br>&amp;nbsp;&amp;nbsp;turtle.turnLeft()<br>&amp;nbsp;&amp;nbsp;return true<br>end<br>function place(n)<br>&amp;nbsp;&amp;nbsp;turtle.select(n)<br>&amp;nbsp;&amp;nbsp;turtle.place()<br>&amp;nbsp;&amp;nbsp;return true<br>end<br>function digRoomLayer(width, PT)<br>&amp;nbsp;&amp;nbsp;for i=1, width-2 do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mineForward(i)<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;turtle.turnLeft()<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mineForward(i)<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;turtle.turnLeft()<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;for i=1, 3 do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mineForward((n-1)/2+1)<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if PT then<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;turnAround()<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;place(1)<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;turnAround()<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mineForward((n-1)/2)-1)<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;turtle.turnLeft()<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;mineForward(2)<br>&amp;nbsp;&amp;nbsp;turtle.turnRight()<br>&amp;nbsp;&amp;nbsp;backUp(1)<br>&amp;nbsp;&amp;nbsp;if PT then<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;place(1)<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;backUp((n-1)/2-1)<br>&amp;nbsp;&amp;nbsp;return true<br>end<br>function digRoom(width, height)<br>&amp;nbsp;&amp;nbsp;digRoomLayer(width, true)<br>&amp;nbsp;&amp;nbsp;for i=1, height-1 do<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mineDown(1)<br>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;digRoomLayer(width, false)<br>&amp;nbsp;&amp;nbsp;end<br>&amp;nbsp;&amp;nbsp;return true<br>end[/spoiler]

test

os.loadAPI("miner")
miner.mineForward(10)
miner.mineUp(1)
miner.digRoom(5, 3)
miner.turnAround()
miner.mineForward(10)
miner.turnAround()
miner.mineUp(1)
os.unloadAPI("miner")

Any help would be very appreciated.
BigSHinyToys #2
Posted 07 June 2012 - 06:30 AM
Spoiler

function mineForward1()
  while(turtle.forward()==false) do
	turtle.dig()
	sleep(0.3)
  end
  return true
end
function mineForward(n)
  local i = 0
  while(i&amp;lt;n) do
	mineForward1()
	i = i + 1
  end
  return true
end
function mineUp1()
  while(turtle.up()==false) do
	turtle.digUp()
	sleep(0.3)
  end
  return true
end
function mineUp(n)
  local i = 0
  while(i&amp;lt;n) do
	mineUp1()
	i = i + 1
  end
  return true
end
function mineDown1()
  while(turtle.down()==false) do
	turtle.digDown()
	sleep(0.3)
  end
  return true
end
function mineDown(n)
  local i = 0
  while(i&amp;lt;n) do
	mineDown1()
	i = i + 1
  end
  return true
end
function backUp(n)
  local i = 0
  while(i&amp;lt;n) do
	while(turtle.back()==false) do
	  sleep(0.1)
	end
	i = i + 1
  end
  return true
end
function turnAround()
  turtle.turnLeft()
  turtle.turnLeft()
  return true
end
function place(n)
  turtle.select(n)
  turtle.place()
  return true
end
function digRoomLayer(width, PT)
  for i=1, width-2 do
	mineForward(i)
	turtle.turnLeft()
	mineForward(i)
	turtle.turnLeft()
  end
  for i=1, 3 do
	mineForward((n-1)/2+1)
	if PT then
	  turnAround()
	  place(1)
	  turnAround()
	end
	mineForward((n-1)/2)-1)
	turtle.turnLeft()
  end
  mineForward(2)
  turtle.turnRight()
  backUp(1)
  if PT then
	place(1)
  end
  backUp((n-1)/2-1)
  return true
end
function digRoom(width, height)
  digRoomLayer(width, true)
  for i=1, height-1 do
	mineDown(1)
	digRoomLayer(width, false)
  end
  return true
end
i have fixed your formatting. the spoilers go on the out side or a code bracket.
eg

[spoiler]
[CODE]
x = "bla bla ect"
[*/CODE]
[*/spoiler]
ignore the * symble.

I will have a quick look through your code.

so i have looked it over and found a few problems I have commented changes I have made. also i have it set up for testing in the same file. this way errors point directly to the line that needs fixing.
here is the altered code
Spoiler

function mineForward1()
while(turtle.forward()==false) do
  turtle.dig()
  sleep(0.3)
end
return true
end
function mineForward(n) -- fixed here
for i = 1, n do
  mineForward1()
end
return true
end
function mineUp1()
while(turtle.up()==false) do
  turtle.digUp()
  sleep(0.3)
end
return true
end
function mineUp(n) -- fixed here
for i = 1, n do
  mineUp1()
end
return true
end
function mineDown1()
while(turtle.down()==false) do
  turtle.digDown()
  sleep(0.3)
end
return true
end
function mineDown(n) -- fixed here
for i = 1, n do
  mineDown1()
end
return true
end
function backUp(n) -- fixed here
for i = 1, n do
  while(turtle.back()==false) do
   sleep(0.1)
  end
end
return true
end
function turnAround()
turtle.turnLeft()
turtle.turnLeft()
return true
end
function place(n)
turtle.select(n)
turtle.place()
return true
end
function digRoomLayer(width, PT) -- what is the var "n" in this functions perpous??
for i=1, width-2 do
  mineForward(i)
  turtle.turnLeft()
  mineForward(i)
  turtle.turnLeft()
end
for i=1, 3 do
  mineForward((n-1)/2+1)
  if PT then
   turnAround()
   place(1)
   turnAround()
  end
  mineForward(((n-1)/2)-1) -- missed a "(" here
  turtle.turnLeft()
end
mineForward(2)
turtle.turnRight()
backUp(1)
if PT then
  place(1)
end
backUp((n-1)/2-1)
return true
end
function digRoom(width, height)
digRoomLayer(width, true)
for i=1, height-1 do
  mineDown(1)
  digRoomLayer(width, false)
end
return true
end
--os.loadAPI("miner")
mineForward(10)
mineUp(1)
digRoom(5, 3)
turnAround()
mineForward(10)
turnAround()
mineUp(1)
--os.unloadAPI("miner")