Jump to content




Repeating a program.


  • You cannot reply to this topic
2 replies to this topic

#1 DELETEDACCOUNTPLZREMOVE

  • Members
  • 3 posts

Posted 10 April 2015 - 02: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

#2 SquidDev

    Frickin' laser beams | Resident Necromancer

  • Members
  • 1,427 posts
  • LocationDoes anyone put something serious here?

Posted 10 April 2015 - 02: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.

#3 DELETEDACCOUNTPLZREMOVE

  • Members
  • 3 posts

Posted 10 April 2015 - 02:23 PM

Thanks so much for your help! It worked!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users