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

Help with repeat (simple)

Started by astonish01, 26 October 2015 - 12:03 AM
astonish01 #1
Posted 26 October 2015 - 01:03 AM
This is simple. I want a turtle to keep checking for a block on top of it, then run the rest of the code.

What I have already tried:

repeat turtle.detectUp() until turtle.detectUp()
then it runs the code, I also tried

repeat turtle.detectUp() until turtle.detectUp() = true
Edited on 26 October 2015 - 12:04 AM
Anavrins #2
Posted 26 October 2015 - 01:49 AM
Replace the first turtle.detectUp() with sleep(1).
Running you code will most likely lead to your turtle crashing, a sleep will prevent it.
astonish01 #3
Posted 26 October 2015 - 03:30 AM
Replace the first turtle.detectUp() with sleep(1).
Running you code will most likely lead to your turtle crashing, a sleep will prevent it.
Thanks, worked, but if I you could answer another question please, i'm trying to for example ask a user to input a number, with the ( read() ) thing, and the subtract 64 from that number, and even tho the user inputs a number, it gives me this error:

""program name":3 attempt to compare string with
number expected, got string"
Actual testing code:

print("test")
local t1 = ( read() )
if t1 > 64 then
t1 = t1-64
else
print(t1)
end
print(t1)
Bomb Bloke #4
Posted 26 October 2015 - 03:38 AM
You can convert string-types to number-types:

local t1 = tonumber(read())

Though if the string doesn't represent a valid number, tostring() will return nil. So to deal with that, you might do:

local t1
repeat t1 = tonumber(read()) until t1  -- Keep bugging the user to type stuff until t1 is not nil.