Posted 17 July 2012 - 02:38 AM
Okay, so I'm trying to write a program that will count the contents of a chest when I send a rednet message. Leaving out that part, I have this:
The Back redstone goes to an AND gate which allows a timer pulse to drive a transposer and that hooks to an item detector which is wired to Right. Front goes to a splitter which interrupts EU flow to an energy link powering a wooden transport pipe to put the stuff back into the primary chest when it's done.
The program SHOULD be counting pulses until there's a 2 second gap but it never stops. Adding in another line inside getpulse() tells me that it's not even reading any pulses. I have a modem connected to Left which I can turn on and off so I know the input side is correctly set to Right.
Right off the bat I can see I need to start the timer before doing my while loop at the bottom or else an empty inventory will never trigger the timer event but still, why isn't my counter incrementing at all?
- Snowsong
** EDIT **
Adding in the timer = os.setTimer(2) line before the parallel process while loop results in a program I can't even terminate and I have to reboot the computer to stop it now.
local time = 0
local count = 0
local timer
function getpuse()
if rs.getInput("right") then
while rs.getInput("right") do
sleep(0.1) -- wait for pulse to end
end
count = count + 1
timer = os.startTimer(2)
end
end
function tout()
local event, param
while time == 0 do
event, param = os.pullEvent()
if event == "timer" and param == timer then
time = 1
end
end
end
rs.setOutput("back", true)
while time == 0 do
parallel.waitForAny(tout(), getpulse())
end
rs.setOutput("back", false)
rs.setOutput("front", false)
sleep(10)
rs.setOutput("front", true)
term.write(count)
The Back redstone goes to an AND gate which allows a timer pulse to drive a transposer and that hooks to an item detector which is wired to Right. Front goes to a splitter which interrupts EU flow to an energy link powering a wooden transport pipe to put the stuff back into the primary chest when it's done.
The program SHOULD be counting pulses until there's a 2 second gap but it never stops. Adding in another line inside getpulse() tells me that it's not even reading any pulses. I have a modem connected to Left which I can turn on and off so I know the input side is correctly set to Right.
Right off the bat I can see I need to start the timer before doing my while loop at the bottom or else an empty inventory will never trigger the timer event but still, why isn't my counter incrementing at all?
- Snowsong
** EDIT **
Adding in the timer = os.setTimer(2) line before the parallel process while loop results in a program I can't even terminate and I have to reboot the computer to stop it now.