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

program help

Started by CLASnipe, 20 July 2015 - 04:39 AM
CLASnipe #1
Posted 20 July 2015 - 06:39 AM
First off I wanna say i'm not big on writing code but I wanted to make a simple program to place cake above a turtle but I cant seem to get it to work when I run the startup.

http://gyazo.com/5f67596ba024334438d9e479cdd9786a

i'm trying to get it to place cake on top of itself when it detects nothing above it any ideas or help would be appreciated
HPWebcamAble #2
Posted 20 July 2015 - 06:52 AM
You've got a very simple problem:

When 'turtle.detectUp()' is true, that means there IS something there.
You need to invert what it returns


if not turtle.detectUp() then
  turtle.placeUp()
end

If you'd like it to check every few seconds, instead of just when the computer starts,
you can do this:

while true do --# true will always be true, so it loops forever
  if not turtle.detectUp() then
    turtle.placeUp()
  end
  sleep(5) --# Waits 5 seconds
end