Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tOpen = { left = false, right = false, top = false, bottom = false, front = false, back = false }
- local tValid = { left = true, right = true, top = true, bottom = true, front = true, back = true }
- function open( sSide )
- if type( sSide ) ~= "string" then
- error( "string expected" )
- end
- if not tValid[sSide] then
- error( "Invalid side" )
- end
- tOpen[ sSide ] = true
- end
- function close( sSide )
- if type( sSide ) ~= "string" then
- error( "string expected" )
- end
- if not tValid[sSide] then
- error( "Invalid side" )
- end
- tOpen[ sSide ] = false
- end
- function send( sID, sMessage )
- local hasSent = false
- for i,v in pairs( tOpen ) do
- if v == true then
- local sCable = peripheral.wrap( i )
- sCable.send( sID, sMessage )
- hasSent = v
- end
- end
- return hasSent
- end
- function broadcast( sMessage )
- return send( -1, sMessage )
- end
- function announce()
- return broadcast( "" )
- end
- function receive( sTimeOut )
- local timer = nil
- local sEvent = "cable_message"
- if nTimeout then
- timer = os.startTimer( nTimeout )
- sEvent = nil
- end
- while true do
- local e, p1, p2, p3 = os.pullEvent( sEvent )
- if e == "cable_message" then
- return p1, p2, p3
- elseif e == "timer" and p1 == timer then
- return nil, nil, nil
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment