Jump to content




Train Stopper


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

#1 X3ME

  • Members
  • 82 posts
  • LocationBeing the stereotypical kid in forums.

Posted 11 September 2014 - 11:56 AM

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

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 11 September 2014 - 12: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


#3 X3ME

  • Members
  • 82 posts
  • LocationBeing the stereotypical kid in forums.

Posted 11 September 2014 - 01:20 PM

 KingofGamesYami, on 11 September 2014 - 12:27 PM, said:

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

 KingofGamesYami, on 11 September 2014 - 12:27 PM, said:

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

#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 11 September 2014 - 01: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 by KingofGamesYami, 11 September 2014 - 01:51 PM.


#5 X3ME

  • Members
  • 82 posts
  • LocationBeing the stereotypical kid in forums.

Posted 11 September 2014 - 01:53 PM

 KingofGamesYami, on 11 September 2014 - 01:51 PM, said:

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





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users