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

Program that toggles its function every time?

Started by Kghareus, 21 December 2012 - 09:02 AM
Kghareus #1
Posted 21 December 2012 - 10:02 AM
I would like to know if its possible with turtles to have a program that, every time you run it, it toggles to a different function. For example, a door program. When it runs the first time, the turtle digs out a door. Then, the second time it runs, it rebuilds the door for you. Then, the third time it will dig out the door again, and so on.
OmegaVest #2
Posted 21 December 2012 - 10:11 AM
Well, yes if you only want to do that. And I don't think it will ever work on a door, but you can always break open the wall beside the door (if there's nothing there)


if turtle.detect() then
   turtle.dig()
   turtle.forward()  --  OR turtle.up()
   turtle.digUp()    -- OR turtle.dig()
   turtle.forward()  -- OR turtle.down()
   turtle.turnRight()  -- Remove for secondary purpose
   turtle.turnRight()  -- Remove for secondary purpose
else
   turtle.forward()  -- OR turtle.up()
   turtle.placeUp()  -- OR turtle.place()
   turtle.forward()  -- OR turtle.down()

   turtle.turnLeft()  -- Remove for secondary purpose
   turtle.turnLeft()  --  Remove for secondary purpose
   turtle.place() 
end

I am, of course, assuming this is meant to go through said door. If not, and it is meant to act as the door-opening mechanism, then use the commented code.

Also, remember: this will not work for actual doors. Walls, yes, doors no.
Kghareus #3
Posted 21 December 2012 - 10:12 AM
Well, yes if you only want to do that. And I don't think it will ever work on a door, but you can always break open the wall beside the door (if there's nothing there)


if turtle.detect() then
   turtle.dig()
   turtle.forward()  --  OR turtle.up()
   turtle.digUp()	-- OR turtle.dig()
   turtle.forward()  -- OR turtle.down()
   turtle.turnRight()  -- Remove for secondary purpose
   turtle.turnRight()  -- Remove for secondary purpose
else
   turtle.forward()  -- OR turtle.up()
   turtle.placeUp()  -- OR turtle.place()
   turtle.forward()  -- OR turtle.down()

   turtle.turnLeft()  -- Remove for secondary purpose
   turtle.turnLeft()  --  Remove for secondary purpose
   turtle.place()
end

I am, of course, assuming this is meant to go through said door. If not, and it is meant to act as the door-opening mechanism, then use the commented code.

Also, remember: this will not work for actual doors. Walls, yes, doors no.
Thanks for the quick reply, and yes by door I meant wall.