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

Train Stopper

Started by X3ME, 11 September 2014 - 10:56 AM
X3ME #1
Posted 11 September 2014 - 12:56 PM
Hey,
I have written this small program:

if rs.getInput("back", true) then
sleep(5)
redstone.setOutput("left", false)
sleep(5)
redstone.setOutput("left", true)
end

But it doesnt work!
The porpuse is stopping the minecart 5 seconds after receiving a pulse and starting it 5 secounds later…

Thanks!

PS: I cannot restart the program if it receives a pulse during the program is running
KingofGamesYami #2
Posted 11 September 2014 - 01:27 PM
shouldn't you have a loop here? Also, having a sleep( 5 ) after the if statement will make it pause for 5 seconds between getting a redstone signal and outputting one.

while true do
  os.pullEvent( "redstone" )
  if rs.getInput( "back" ) then
    rs.setOutput( "left", true )
    sleep( 5 )
    rs.setOutput( "left", false )
  end
end
X3ME #3
Posted 11 September 2014 - 02:20 PM
shouldn't you have a loop here? Also, having a sleep( 5 ) after the if statement will make it pause for 5 seconds between getting a redstone signal and outputting one.

while true do
  os.pullEvent( "redstone" )
  if rs.getInput( "back" ) then
	rs.setOutput( "left", true )
	sleep( 5 )
	rs.setOutput( "left", false )
  end
end

Yes, i should have a loop, i dont know how to make a loop

shouldn't you have a loop here? Also, having a sleep( 5 ) after the if statement will make it pause for 5 seconds between getting a redstone signal and outputting one.

while true do
  os.pullEvent( "redstone" )
  if rs.getInput( "back" ) then
	rs.setOutput( "left", true )
	sleep( 5 )
	rs.setOutput( "left", false )
  end
end

By the way,
I want theprogram to wait 5 secounds before redstone output = false
KingofGamesYami #4
Posted 11 September 2014 - 02:51 PM
Yes, but the way you had it here is what would happen:

1) program starts
2) checks if redstone input
3-1) if not, program ends
3-2) if so, waits 5 seconds
4) outputs redstone signal for 5 seconds
5) program ends

With mine:
1) program starts
2) program waits for a redstone change
3-1) if not redstone input, goto step 2
3-2) if redstone signal, turn on redstone for 5 seconds
4) goto step 2

Any questions?
Edited on 11 September 2014 - 12:51 PM
X3ME #5
Posted 11 September 2014 - 02:53 PM
Yes, but the way you had it here is what would happen:

1) program starts
2) checks if redstone input
3-1) if not, program ends
3-2) if so, waits 5 seconds
4) outputs redstone signal for 5 seconds
5) program ends

With mine:
1) program starts
2) program waits for a redstone change
3-1) if not redstone input, goto step 2
3-2) if redstone signal, turn on redstone for 5 seconds
4) goto step 2

Any questions?

No, thanks :D/>