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

[Solved] No idea what I'm doing wrong....

Started by lieudusty, 28 July 2012 - 12:44 AM
lieudusty #1
Posted 28 July 2012 - 02:44 AM
Hi everyone! :)/>/>

I'm making a turtle program that asks you how deep you want to mine and it will mine. I made function to check of its the input is a number and I'm getting the error:

bad agrument: string expected, got nill
I have no idea how to fix this. Can someone please help?

Code:

-- Functions --
function isNumber(number)
for i = 1, string.len(number) do
  char = string.sub(number, i, i)
	if (char == "1") or (char == "2") or (char == "3") or (char == "4") or (char == "5") or (char == "6") or (char == "7") or (char == "8") or (char == "9") or (char == "0") then
	 if i == string.len(number) then
	  return true
	 else
	 end
	else
	 return false
	end
   end
end
dig = function()
  turtle.dig()
  turtle.digUp()
  turtle.digDown()
end
-- Variables --
d = 0
b = 0
-- Main Code --
print("How deep would you like to mine?")
rawin = read()
if isNumber(raw) then
  pinput= tonumber(rawin)
  while d ~= pinput do
  dig()
  turtle.forward()
  d = d+1
  end
  turtle.turnRight()
  turtle.forward()
  turtle.turnRight()
  while b ~= pinput+1 do
  dig()
  turtle.forward()
  b = b+1
  print("Mining Complete!")
end
else
print("That's not a valid number!")
os.sleep(1.5)
term.clear()
term.setCursorPos(1,1)
end
Luanub #2
Posted 28 July 2012 - 03:57 AM
On this line you use the var raw, I don't see it being declared anywhere or having any value assigned to it.



if isNumber(raw) then


I think you may have meant to use rawin instead of raw? If not you will need to declare raw.
lieudusty #3
Posted 28 July 2012 - 06:23 AM
On this line you use the var raw, I don't see it being declared anywhere or having any value assigned to it.



if isNumber(raw) then


I think you may have meant to use rawin instead of raw? If not you will need to declare raw.
Cool thanks so much!