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

Receiving error "0/bios:48: bad argument: string expected, got nil"

Started by Himself12794, 22 November 2012 - 02:19 PM
Himself12794 #1
Posted 22 November 2012 - 03:19 PM
Hello, I am relatively new to ComputerCraft, and I wrote a program to run a frames quarry and received the above error.
Here is my code:

function askDepth()
  write("How deep? --> ")
  local x=read()
  term.clear()
  term.setCursorPos(1,1)
  if x==0 then
	local ans=""
	print("Do you want to cancel excavation? yes/no")
	ans=read()
	  if ans=="yes" then
		shell.exit()
	  else if ans=="no" then
		print("Exiting program...")
		sleep(1.5)
		shell.exit()
	  else
		print("Answer not recognized, exiting program...")
		sleep(1.5)
		shell.exit()
	  end
  end
end
function breakBlocks()
  rs.setOutput('top', true)
  print("Excavating...")
  sleep(0.4)
  rs.setOutput('top', false)
end
function moveNorth()
  rs.setOutput('back', true)
  print("Moving North...")
  sleep(1.6 )
  rs.setOutput('back', false)
end
function moveDown()
  rs.setOutput('right', true)
  print("Moving Down...")
  sleep(1.6)
  rs.setOutput('right', false)
end
function moveSouth()
  rs.setOutput('left', true)
  print("Moving South")
  sleep(1.6)
  rs.setOutput('left', false)
end
function excavate()
  moveNorth()
  breakBlocks()
  moveSouth()
  breakBlocks()
  moveDown()
  term.clear()
  term.setCursorPos(1,1)
end
write("Note: Until the PhilQuarry program is")
write(" updated, it excavates only a 6x8 area,")
print(" and only moves south and north.")
print("")
--write("How deep?: ")
--local x=read()
--term.clear()
--term.setCursorPos(1,1)
askDepth()
write("0/")
write(x)
print(" Layer(s) Excavated")
for i=1, x do
  excavate()
  write(i)
  write("/")
  write(x)
  print(" Layer(s) Excavated")
end

term.clear()
term.setCursorPos(1,1)
write(x)
write("/")
write(x)
print(" Layers Excavated")
sleep(1.5)
print("Excavation Complete")

After I select the depth I want, I get the above error message. It only started after I updated to ComputerCraft 1.4. Also, before updating, I couldn't get the cancellation part of askDepth() to work. Can anyone see the problem? Thanks in advance!
OmegaVest #2
Posted 22 November 2012 - 03:46 PM
You commented out x without commenting out the write that calls x. Thus, when it asks for a string, and finds nothing, it fails.

The clue here is that it prints 0/, but then crashes.


EDIT: I think print may have a try/catch for that, but I cannot remember. I know write does not.
Himself12794 #3
Posted 22 November 2012 - 04:40 PM
Thank you! I just removed the local definition from the x var in askDepth and it seems to work fine now.