Jump to content




Help with repeat (simple)


3 replies to this topic

#1 astonish01

  • Members
  • 33 posts

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 by astonish01, 26 October 2015 - 01:04 AM.


#2 Anavrins

  • Members
  • 775 posts

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.

#3 astonish01

  • Members
  • 33 posts

Posted 26 October 2015 - 03:30 AM

View PostAnavrins, on 26 October 2015 - 01:49 AM, said:

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)


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users