83 posts
Location
Being the stereotypical kid in forums.
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
3057 posts
Location
United States of America
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
83 posts
Location
Being the stereotypical kid in forums.
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
3057 posts
Location
United States of America
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
83 posts
Location
Being the stereotypical kid in forums.
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/>