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

Rain Program

Started by SullyPlayer, 02 July 2014 - 05:31 PM
SullyPlayer #1
Posted 02 July 2014 - 07:31 PM
So I've made a program to turn off the rain using the rainmaker from forestry. I run my program, but my turtle does not appear to care that the turtle.detect() is false. It's clearly something wrong with my program. Could I get some advice as to how to fix the problem?

Thanks!!!

The goal of this program is to get it to check for a block, and if there is one, then give the rainmaker a dissipation charge, which it contains in its inventory.


local x
x = 0
while x<9 do
turtle.detect()
if true then turtle.turnRight()
turtle.turnRight()
turtle.drop(1)
sleep(19)
turtle.turnRight()
turtle.turnRight()
if false then sleep(5)
end
end
end
AssossaGPB #2
Posted 02 July 2014 - 07:54 PM
Here:

for x=1,9 do
  if turtle.detect() then
    turtle.turnRight()
    turtle.turnRight()
    turtle.drop(1)
    sleep(19)
    turtle.turnRight()
    turtle.turnRight()
  else
    sleep(5)
  end
end
KingofGamesYami #3
Posted 02 July 2014 - 07:58 PM

local x
x = 0
while x<9 do
 turtle.detect()  --#you are not storing the return
 if true then turtle.turnRight()  --#true is always true...
  turtle.turnRight()
  turtle.drop(1)
  sleep(19)
  turtle.turnRight()
  turtle.turnRight()
  if false then sleep(5) --#false is always false...
  end
 end
end 

Fixed the formatting for you, it's quite obvious what's wrong here.


for i = 1, 9 do --#for loops automatically increment
 local block = turtle.detect()  --#you are not storing the return
 if block then turtle.turnRight()
  turtle.turnRight()
  turtle.drop(1)
  sleep(19)
  turtle.turnRight()
  turtle.turnRight()
  elseif not block then --# not simply inverts the value.  false becomes true, true becomes false.
   sleep(5)
  end
 end
end
Ninja'd by Assossa, but I've got a bit more explanation then he does.

Edit: fixed my code tags
Edited on 02 July 2014 - 05:59 PM
SullyPlayer #4
Posted 02 July 2014 - 08:25 PM
That isn't quite what I wanted. I want it to keep checking for the rain until it occurs, so that when it does, it turns off the rain and then starts checking again. I'm using a rain sensor from project red to send a redstone signal to my piston forcing a block down for the turtle to detect.

Sorry!
Edited on 02 July 2014 - 06:29 PM