You could write a function that checks if a bundled cable's state has changed and then generate your own event for that by making use of
os.queueEvent.
Edit: Just to prevent any misunderstanding: Everytime redstone signals change, the "redstone" event is created which you'd then use to create your custom event, along with the changes that actually occurred within the bundled cable in question.
Edit 2: Here's a little example of how you could achieve this (although as you will notice, I didn't make use of
os.queueEvent at all^^).
Take e.g. this code…
local tCableState = {} -- Holds the state of all bundled cables on the computer.
-- Get the current state for all 6 sides.
for _, v in pairs( rs.getSides() ) do
tCableState[ v ] = rs.getBundledInput( v )
end
-- If a bundled cable changes its state, then this function returns the event 'bundled_cable' and a table.
-- The returned table contains only sides that have changed and it has this format: { side = { new_value, old_value } }
function pullEvent()
local bStatesChanged = false
local tChangedCables = {}
local event, p1, p2, p3, p4, p5 = os.pullEvent()
if event == "redstone" then
-- Iterate over all 6 sides of the computer.
for _, v in pairs( rs.getSides() ) do
local nBCInput = rs.getBundledInput( v ) -- Get cable input for current side.
if nBCInput ~= tCableState[ v ] then -- Has the state changed?
tChangedCables[ v ] = { nBCInput, tCableState[ v ] } -- Add the changed side + its new and old values to the return table.
tCableState[ v ] = nBCInput -- Update the local state table.
bStatesChanged = true
end
end
end
-- Turn the 'redstone' event into a 'bundled_cable' event if the state of a bundled cable has changed.
if bStatesChanged then
event = "bundled_cable"
p1 = tChangedCables
end
return event, p1, p2, p3, p4, p5
end
… and save it as '
bc' or something.
We're going to use this as an API, to save the state of the bundled cables across programs.
Then make another program with this example-code and replace '
bc' (at beginning and middle of the code) with whatever you named the API above…
-- Load API
if not os.loadAPI( "bc" ) then
error( "Bundled-Cable Event API could not be loaded. :unsure:/>/>" )
end
while true do
local sEvent, p1, p2, p3, p4, p5 = bc.pullEvent() -- Here we call our customized event listener bc.pullEvent(), instead of os.pullEvent()
if sEvent == "bundled_cable" then
-- p1 will contain a table with all the sides that have changed, mapped to their new and old values, i.e. p1 := { "side" = { new_value, old_value } }
local new = 1
local old = 2
for side, tValue in pairs( p1 ) do
print( "\""..side.."\" has changed from "..tValue[ old ].." to "..tValue[ new ] )
end
end
if sEvent == "char" and string.lower( p1 ) == "q" then break end
end
Start it and change the state of some bundled cables.
It should tell you exactly what cable changed and to what it changed.
bc.pullEvent function returns a table with
key = side ( that changed ),
value = { new value, old value }.
Writing this it just came to my mind that it might be useful to return the former state, which would just be a trivial change in the code.
If you find the above code useful at all for your purposes and would like to have the former state of the bundled cable be returned as well, just give me a holler. B)/>/>
Edit: I've changed the return table, so that now it not only contains the new but also the old value.Edit: Changed tCableState to not use a numerical index for its keys, but the side-strings of rs.getSides()