Run sleep on the sideline
#1
Posted 14 October 2012 - 02:31 PM
You have a program that outputs to a redstone output, sleeps for 5 seconds, then turns the output off.
Then you have code that should run when the redstone output starts, (for example when a door opens), but not be affected by the sleep delay, (because then when the sleep is over, the door would be closed. If theres any way to do this, please tell me
Thanks
#2
Posted 14 October 2012 - 02:33 PM
I haven't done any testing with it yet, but I believe, based upon what I've read, it should be what you're looking for.
http://computercraft...=Parallel_(API)
Edit:
Or, you could do something like.
rs.setOutput("back", true)
for i = 1, 5 do
--Unaffected sleep code.
sleep(1)
end
rs.setOutput("back", false)
Edited by JoshhT, 14 October 2012 - 02:37 PM.
#3
Posted 14 October 2012 - 02:35 PM
#4
Posted 14 October 2012 - 02:37 PM
#5
Posted 14 October 2012 - 02:53 PM
#6
Posted 14 October 2012 - 03:34 PM
#7
Posted 14 October 2012 - 06:43 PM
#8
Posted 15 October 2012 - 10:24 PM
Lyqyd, on 14 October 2012 - 06:43 PM, said:
Can you please pass on some code examples for this? I'm not great at coding.
Thanks
#9
Posted 16 October 2012 - 07:29 AM
os.startTimer(desired timeout)
#10
Posted 16 October 2012 - 10:09 PM
Doyle3694, on 16 October 2012 - 07:29 AM, said:
os.startTimer(desired timeout)
Um... still a bit lost
#11
Posted 16 October 2012 - 10:18 PM
The syntax would be different depending on what you want to do really
#12
Posted 17 October 2012 - 01:45 PM
Doyle3694, on 16 October 2012 - 10:18 PM, said:
The syntax would be different depending on what you want to do really
Well, The code is imbeded in different things, but the features are basically
Menu (using Window API) with some options
Door 1
Door 2
Door 2 is behind door 1. You open door 1, and after 6 seconds it closes. However, the door is on it's own timer, instead of mine (in the real area, the door is actually a piston staircase, so this is easier), and then door 2 is a standard door, that is opened and closed by redstone from the computer.
Additionally, theres a monitor that projects, from rednet connections, the stats of the doors.
The sleeping issue is that I have the staircase activation code (or door 1) which is a 1 second pulse, and then it projects the data to rednet, delays 6 seconds, then projects the updated data to rednet.
This causes the issue of when I want to activate the staircase, then activate the door (2) very close together. However, the issue is that when I open the staircase, I have to wait about 7s (door open pulse + 6 rednet send wait) and THEN I can open the door, meaning by the time the staircase is closed.
#13
Posted 17 October 2012 - 02:29 PM
#15
Posted 17 October 2012 - 02:42 PM
--draw window...
rednet.open("top")
shell.run('mem/redworks/apis/redworks')
redworks.showWindow(12,6,25,8,"Security","1. Alarmn2. Staircasen3. Main Doorsn4. Lab Doorsn5. Quit")
term.setCursorPos(1,16)
write"Choose a selection: "
input = read() --After entry, you cannot open a different door until I run doGui() (which is this whole function) again.
elseif input == "2" then --If they choose option 2 (Staircase)
rs.setBundledOutput("left", colors.red)
sleep(1) --one second pulse
rs.setBundledOutput("left", rs.getBundledOutput("left") - colors.red)
rednet.send(4, "stair on") --Send the Stair On thing
sleep(6) --Wait 6 seconds for the staircase to shut
rednet.send(4, "stair off") --Tell monitor that the stairs are closed
term.setCursorPos(1,16)
term.clearLine()
write("Staircase opened.") --Tell the user that the door is opened
term.clear()
doGui()
elseif input == "3" then --Option 3 (Door)
rs.setBundledOutput("left", colors.orange)
rednet.send(0, "main on") --Message on
sleep(5) --Wait 5 seconds (This is also why you cant do maindoor and then staircase)
rs.setBundledOutput("left", rs.getBundledOutput("left") - colors.orange) --Off
rednet.send(0, "main off") --doors off,
term.setCursorPos(1,16)
term.clearLine()
write("Main doors opened.") --Print to user
sleep(2)
term.clear()
doGui() --Reset back to main selection window
else
term.setCursorPos(1,16)
term.clearLine()
write("Invalid Option")
sleep(0.5)
term.setCursorPos(1,17)
write("Logging out")
ShowWindow is from the Redworks API
#16
Posted 17 October 2012 - 02:49 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











