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

I Cannot Get My Repeat Loop To Work Properly.

Started by Babz, 23 July 2013 - 10:33 AM
Babz #1
Posted 23 July 2013 - 12:33 PM
I ask the user to input a number then I save that number as tunnel. The problem is that on line 40 the repeat loop is not recognizing tunnel as a number and the loop keeps continuing without stopping.

local function torch()
if x % 5 == 0 then
turtle.select(1)
turtle.turnRight()
turtle.turnRight()
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
end
end
local function chest()
turtle.up()
for y = 1,tunnel + 1 do
turtle.back()
end
turtle.select(2)
for inv = 2, 16 do
turtle.dropDown(64)
end
end

print("how long is the tunnel")
tunnel=read()
x=0
repeat
if turtle.detect() == false then
turtle.forward()
turtle.digUp()
x=x+1
elseif turtle.detect()==true then
repeat
turtle.dig()
turtle.detect()
until turtle.detect()==false
turtle.forward()
turtle.digUp()
x=x+1
end
torch()
until x==tunnel – problem is here
print (x)
chest()
Lyqyd #2
Posted 23 July 2013 - 08:47 PM
Split into new topic.


local tunnel = tonumber(read())
--# converts the string returned by read into a number
xKYLERxx #3
Posted 24 July 2013 - 10:24 PM
read() returns a string. Be sure to parse it using


tonumber(read())

xKYLERxx