Hey happy2pester,
I gave it a try, too. Here's the function code:
-- sSide - The side of the computer/turtle that is to be checked.
-- nColor - The color value to be checked for.
-- nTimeframe - The duration (in seconds) for how long the bundled input is being checked for pulses.
-- nTargetPulseCount - The number of pulses that have to be reached within the given time frame for the function to return true.
function checkPulse( sSide, nColor, nTargetPulseCount, nTimeframe )
local nCounter = 0 -- Initialize pulse counter.
local listenTimer = os.startTimer( nTimeframe ) -- Start timer.
-- Event Loop.
while true do
local sEvent, param1 = os.pullEvent() -- Wait for an event.
if sEvent == "redstone" and rs.getBundledInput( sSide ) ~= nColor then
print( "Color turned OFF" ) -- DEBUG-OUTPUT
end
if sEvent == "redstone" and rs.getBundledInput( sSide ) == nColor then
nCounter = nCounter + 1
print( "Color turned ON, Count: "..nCounter ) -- DEBUG-OUTPUT
end
if sEvent == "timer" and param1 == listenTimer then
if nCounter < nTargetPulseCount then -- Compare the amount of counted pulses with the desired target count.
return false -- Counted pulses were less than desired.
else
return true -- Counted pulses were at least as much as desired.
end
end
end
end
And here's an example with which you can test it.
The first line is basically like saying: "Check on the
left side of the computer/turtle if the
gray signal is pulsed at least
3 times within
10 seconds."
local bResult = checkPulse( "left", colors.gray, 3, 10 )
print( "The number of pulses were reached: "..tostring(bResult) ) -- Prints "true" or "false" depending on the outcome of checkPulse().
I have one question though:Do you want to check if the bundled cable is
set to color gray? Or if the color is
part of of the cable (i.e. is only one of the colors that run through the cable)?
At the moment I check only if the comblete cable is
set to the desired color. But if you acutally want the latter, then let me know and I'll gladly change it (or just add it as an additional option, so one can switch between the modes).
Cheers :mellow:/>/>