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:15 AM
jakeb89 #1
Posted 07 June 2012 - 04:15 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()
  while(turtle.forward()==false) do
	turtle.dig()
	sleep(0.3)
  end
  return true
end
function mineForward(n)
  local i = 0
  while(i<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<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<n) do
	mineDown1()
	i = i + 1
  end
  return true
end
function backUp(n)
  local i = 0
  while(i<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

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.
cant_delete_account #2
Posted 07 June 2012 - 04:22 AM
Please give me the code for the API too please.
Never mind, didn't read the whole OP. XD
cant_delete_account #3
Posted 07 June 2012 - 04:24 AM
Is the API on the disk or the main computer?
jakeb89 #4
Posted 07 June 2012 - 04:27 AM
Is the API on the disk or the main computer?

Both exist in both places (I copy them directly after any edits.)

I get the same error in both places. : P
cant_delete_account #5
Posted 07 June 2012 - 04:31 AM
Is the API on the disk or the main computer?

Both exist in both places (I copy them directly after any edits.)

I get the same error in both places. : P
Try using miner = assert(loadfile("disk/miner")) then remove os.unloadAPI and os.loadAPI
jakeb89 #6
Posted 07 June 2012 - 04:33 AM
Is the API on the disk or the main computer?

Both exist in both places (I copy them directly after any edits.)

I get the same error in both places. : P
Try using miner = assert(loadfile("disk/miner")) then remove os.unloadAPI and os.loadAPI

My error is now down to just

test:3: attempt to index ? (a nil value)
cant_delete_account #7
Posted 07 June 2012 - 04:36 AM
–snip–
My error is now down to just

test:3: attempt to index ? (a nil value)
That means the function you're calling doesn't exist. (or a function that the function is calling doesn't exist)
jakeb89 #8
Posted 07 June 2012 - 04:37 AM
–snip–
My error is now down to just

test:3: attempt to index ? (a nil value)
That means the function you're calling doesn't exist. (or a function that the function is calling doesn't exist)

I'm pretty sure mineForward does in fact exist. : / (that's what's on line 3 specifically, there's a whitespace line on line 2.)

Edit: HOLD THE PHONE I FOUND IT. Extra close paren in miner. DERP.

Edit2: Great. Different error now.

test:3: attempt to index ? (a function value)

Edit3: switched back to os.loadAPI("miner"). Seems to have done the job. Also changed "n" to "width" in miner in some places.