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:
Code:
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