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

Repeating a program.

Started by Benaclejames, 10 April 2015 - 01:11 PM
Benaclejames #1
Posted 10 April 2015 - 03:11 PM
I expect that this is a bit of a noob question but here we go…
Recently, I've been having trouble trying to repeat a command.
I need to repeat this program once it's been executed. But so it only repeats when there is a Redstone signal detected.

Command:

while true do
event = os.pullEvent()
if event == "redstone" then
break
end
end

function forwardNum(blocks)
  for i= 1, blocks do
	turtle.forward()
  end
end

turtle.refuel(25)
turtle.up()
turtle.turnLeft()
turtle.turnLeft()
forwardNum(1)
turtle.dig()
forwardNum(2)
turtle.turnRight()
turtle.turnRight()
turtle.down()
turtle.down()
turtle.down()
turtle.dig()
turtle.select(3)
turtle.drop()
turtle.up()
turtle.up()
turtle.up()
forwardNum(2)
turtle.turnRight()
turtle.turnRight()
turtle.select(2)
turtle.place()
turtle.turnRight()
turtle.turnRight()
forwardNum(1)
turtle.down()
turtle.select(1)
Please, Someone help xD
SquidDev #2
Posted 10 April 2015 - 03:21 PM
You probably want to do:


if redstone.getOutput("top") then
  break
end
instead of

event = os.pullEvent()
if event == "redstone" then
  break
end

You can always iterate through redstone.getSides() to check for every side. The trouble is that os.pullEvent() will stop execution until something happens - like changing the redstone signal.
Benaclejames #3
Posted 10 April 2015 - 03:23 PM
Thanks so much for your help! It worked!