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

can anyone look at this?

Started by MrDeano, 11 October 2012 - 03:51 AM
MrDeano #1
Posted 11 October 2012 - 05:51 AM
i'm getting this error

attempt to index ? (a nil value)

heres the code

Spoiler

xCoord = -164
zCoord = 195
yCoord = 72
xQuarry = 999
zQuarry = 999
yQuarry = 150
xProgress = 999
zProgress = 999
yProgress = 150
oProgress = 1
xHome = xCoord
zHome = zCoord
yHome = yCoord
yTravel = 85
orientation = 4
orientations = {"north", "east", "south", "west"}
zDiff = {-1, 0, 1, 0}
xDiff = {0, 1, 0, -1}
lineLength = 2
lines = 3
yMin = 999
function inventoryFull()
  turtle.select(9)
  full = turtle.getItemCount(9) > 0
  turtle.select(1)
  return full
end
function left()
  orientation = orientation - 1
  orientation = (orientation - 1) % 4
  orientation = orientation + 1
  turtle.turnLeft()
end
function right()
  orientation = orientation - 1
  orientation = (orientation + 1) % 4
  orientation = orientation + 1
  turtle.turnRight()
end
function moveForward()
  xCoord = xCoord + xDiff[orientation]
  zCoord = zCoord + zDiff[orientation]
  turtle.dig()

  moved = false
  while not(moved) do

	moved = turtle.forward()
  end
end
function moveUp()
  yCoord = yCoord + 1

  turtle.digUp()
  moved = false
  while not(moved) do

	moved = turtle.up()
  end
end
function moveDown()
  yCoord = yCoord - 1
  turtle.digDown()

  moved = false
  while not(moved) do

	moved = turtle.down()
  end

  if yMin > yCoord then

	yMin = yCoord
  end
end
function look(direction)
  while direction ~= orientations[orientation] do

	right()
  end
end
function goto(xTarget, zTarget, yTarget)
  while yTarget < yCoord do

	moveDown()
  end

  while yTarget > yCoord do

	moveUp()
  end

  if xTarget < xCoord then

	look("west")

	while xTarget < xCoord do
  
	  moveForward()

	end
  end
  if xTarget > xCoord then

	look("east")

	while xTarget > xCoord do
  
	  moveForward()

	end
  end

  if zTarget < zCoord then

	look("north")

	while zTarget < zCoord do
  
	  moveForward()

	end
  end
  if zTarget > zCoord then

	look("south")

	while zTarget > zCoord do
  
	  moveForward()

	end
  end
end
function returnItems()
  xProgress = xCoord
  zProgress = zCoord
  yProgress = yCoord
  oProgress = orientation

  goto(xHome, zHome, yTravel)
  goto(xHome, zHome, yHome)

  for i = 1,9 do

	turtle.select(i)

	turtle.drop()
  end
  turtle.select(1)

  goto(xProgress, zProgress, yTravel)
  goto(xProgress, zProgress, yProgress)
  look(orientations[oProgress])
end
function digLine()
  for i = 1,lineLength do

	if inventoryFull() then
  
	  returnItems()

	end

	moveForward()
  end
end
function digLayer()
  for i = 1,lines do

	digLine()

	if (i%2) == 1 and i < lines then
  
	  left()
  
	  moveForward()
  
	  left()

	elseif i < lines then
  
	  right()
  
	  moveForward()
  
	  right()

	end
  end
  goto(xQuarry, zQuarry, yCoord)
  look("north")
  moveDown()
end
function digQuarry(xTarget, zTarget, yTarget)
  xQuarry = xTarget
  zQuarry = zTarget
  yQuarry = yTarget

  goto(xQuarry, zQuarry, yTravel)
  goto(xQuarry, zQuarry, yQuarry)
  look("north")
  while yMin > 7 do

	digLayer()
  end
  goto(xQuarry, zQuarry, yQuarry)
  yMin = 999
end
digQuarry(-170, 210, 70)
Luanub #2
Posted 11 October 2012 - 05:55 AM
What does the rest of the error say? It should list a line number. I'll start looking through the code but the entire error message would help.

EDIT: I think it is due to line 26

return full

It is thinking that full is a variable since it does not have quotes around it and since it is not defined, its erroring.

Try

return "full"
Edited on 11 October 2012 - 03:57 AM
stilldabomb #3
Posted 11 October 2012 - 05:55 AM
*Facepalm* Which line?
EDIT: Ninja'd… :P/>/>
MrDeano #4
Posted 11 October 2012 - 05:57 AM
sorry i called the file new quarry and the rest of the code says

new:131: attempt to index ? (a nil value)
chiloxsan #5
Posted 11 October 2012 - 05:59 AM
I downloaded your program and loaded it onto a mining turtle with fuel. It didn't throw any errors, it just went to a random location and started digging a 3x3 hole. If you can give me a line number, that would be appreciated. Opps, people provided a line number. My bad. Have you changed the code since you last showed it to us?
stilldabomb #6
Posted 11 October 2012 - 06:04 AM
Name it new_quarry, spaces make "quarry" an argument…
Cozzimoto #7
Posted 11 October 2012 - 06:17 AM
you ripped this from youtube didnt you?
MrDeano #8
Posted 11 October 2012 - 07:18 AM
Yes I did but I had to write it by hand so I must of missed somthing
Cozzimoto #9
Posted 11 October 2012 - 01:04 PM
well since you got it from youtube from BSGSamuel why dont you go watch his videos again or go to his video where he has his script he made available for download.
MrDeano #10
Posted 11 October 2012 - 02:29 PM
I did and like I said I copied it but I must off made a spelling mistake but I can not find it
Luanub #11
Posted 11 October 2012 - 09:50 PM
Name it new_quarry, spaces make "quarry" an argument…

Did you do this? new quarry vs new_quarry??
stilldabomb #12
Posted 12 October 2012 - 09:37 AM
Name it new_quarry, spaces make "quarry" an argument…

Did you do this? new quarry vs new_quarry??
Do what? I'm confused…
Luanub #13
Posted 12 October 2012 - 09:54 AM
Name it new_quarry, spaces make "quarry" an argument…

Did you do this? new quarry vs new_quarry??
Do what? I'm confused…

I was wondering if he named it that way, and if so did he did as you suggested and change it. :)/>/>
Zoinky #14
Posted 12 October 2012 - 11:09 AM
Did you do this? new quarry vs new_quarry??
I was wondering if he named it that way, and if so did he did as you suggested and change it. :)/>/>

Why'd you write "vs"? That makes no sense.
Edit: Erm, Never mind. It's still a bit odd.
stilldabomb #15
Posted 29 October 2012 - 05:38 AM
– Mass snip –
Ohhh, ok!