Posted 30 December 2012 - 04:45 PM
Hi there. I seem to be having an issue assigning multiple variables using the read() function. For some reason, I seem to get the error "progtunnel:140: attempt to concatenate sting and nil". I'd really appreaciate if someone could check out my code and help me figure out what i did wrong. And if you're wondering, I'm making a 3x3 tunnel bore with user input for the depth that it digs and I'm slowly figuring out how to auto-check the inventory for full stacks, make it return to the chest it placed, and return to it's last dig cycle and continue digging. So far I'm only about 30% through all that… Oh well. Anyways, the help would be much appreciated, so here's the code I've got so far. I marked the issue lines and have sectioned off all the function defining and chunks and such what.
--Clearing the Screen--
term.clear()
term.setCursorPos(1,1)
print[["3x3 Tunnel Turtle v1.0"
=======================================
]]
--Initial Coordinates--
rednet.open("right")
xcor,ycor,zcor=gps.locate(5)
if xcor~=nil then
print("Starting Coords:")
print("x = "..xcor)
print("y = "..ycor)
print("z = "..zcor)
print(" ")
else
print("GPS System Offline")
error()
end
--Defining checkInv() Function--
local function checkInv()
x=0
for i=1,16 do
turtle.select(i)
x=turtle.getItemCount(i)
if x==64 then
print("Full Slot. Returning to Chest")
--Space for Return Program--
break
else
end
end
end
--User Input for Tunnel Length--
term.write("Length of Tunnel? ")
l,lr=read() --Line that's supposed to define lr to find Distance Traveled--
print(" ")
print("Digging for "..l.. " Cycles.")
print(" ")
--Placment of Chest for Depositing--
turtle.turnLeft()
if turtle.detect()==true then
turtle.select(2)
turtle.dig()
turtle.select(1)
if turtle.getItemCount(1)==1 then
print("Placing Chest.")
turtle.place()
else
print("No Storage Found. Returning.")
error()
end
else
if turtle.getItemCount(1)==1 then
print("Placing Chest.")
turtle.place()
else
print("No Storage Found. Returning.")
error()
end
end
turtle.turnRight()
--Digging Loop and Distance Counter for Returning--
for i=1,l do
if turtle.detect()==true then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
turtle.turnLeft()
for x=1,2 do
if turtle.detect()==true then
turtle.dig()
turtle.turnLeft()
sleep(1)
turtle.turnLeft()
else
turtle.turnLeft()
sleep(1)
turtle.turnLeft()
end
if turtle.detect()==true then
turtle.dig()
turtle.turnRight()
sleep(1)
turtle.turnRight()
else
turtle.turnRight()
sleep(1)
turtle.turnRight()
end
if turtle.detectUp()==true then
turtle.digUp()
turtle.up()
else
turtle.up()
end
end
if turtle.detect()==true then
turtle.dig()
turtle.turnLeft()
sleep(1)
turtle.turnLeft()
else
turtle.turnLeft()
sleep(1)
turtle.turnLeft()
end
if turtle.detect()==true then
turtle.dig()
turtle.turnLeft()
else
turtle.turnLeft()
end
turtle.down()
sleep(1)
turtle.down()
checkInv()
turtle.select(1)
print("Distance Traveled: "..lr) --Line with the Issue--
end