Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local message,senderID
- local MODEM_RS_CHANNEL = 127
- local modems = {}
- --Local function, this isn't part of the API
- local function send(message)
- for i = 1,6 do
- if modems[rs.getSides()[i]] then
- peripheral.call(rs.getSides()[i],"transmit",MODEM_RS_CHANNEL,MODEM_RS_CHANNEL,message)
- end
- end
- end
- --This basically tells the program that this modem can be used for sending and receiving messages.
- function addModem(side)
- modems[side] = true
- peripheral.call(side,"open",MODEM_RS_CHANNEL)
- end
- --This does the opposite of the previous method
- function removeModem(side)
- modems[side] = false
- peripheral.call(side,"open",MODEM_RS_CHANNEL)
- end
- --This returns true if the modem is "connected"
- function isConnected(side)
- if modems[side] then
- return true
- else
- return false
- end
- end
- --This waits for a redstone update to occur on one of the RS bots
- function waitForUpdate()
- message = "event true"
- send(message)
- while message ~= "gotEvent" do
- _,_,_,_,message = os.pullEvent("modem_message")
- end
- message = "event false"
- send(message)
- return
- end
- --[[
- All of these functions work pretty much exactly as the redstone API methods.
- The "output" functions require a "state" argument, for setOutput this would be true or false.
- For setAnalogOutput it would be a number 0-15, bundled would be a number 0-65535, etc.
- They also require a side (the side of the output computer you want to output) and the ID of the output computer.
- "Get" methods just require the last two, and they return the state. testBundledOutput requires all 3 arguments.
- ]]
- function setOutput(bool,side,id)
- message = textutils.serialize("setOutput",bool,side,id)
- send(message)
- end
- function setAnalogOutput(num,side,id)
- message = textutils.serialize("setAnalogOutput",num,side,id)
- send(message)
- end
- function setBundledOutput(num,side,id)
- message = textutils.serialize("setBundledOutput",num,side,id)
- send(message)
- end
- function getInput(side,id)
- message = textutils.serialize("getInput",0,side,id)
- send(message)
- while senderID ~= id do
- _,_,_,senderID,message = os.pullEvent("modem_message")
- end
- senderID,_ = nil
- return message
- end
- function getAnalogInput(side,id)
- message = textutils.serialize("getAnalogInput",0,side,id)
- send(message)
- while senderID ~= id do
- _,_,_,senderID,message = os.pullEvent("modem_message")
- end
- senderID,_ = nil
- return message
- end
- function getBundledInput(side,id)
- message = textutils.serialize("getBundledInput",0,side,id)
- send(message)
- while senderID ~= id do
- _,_,_,senderID,message = os.pullEvent("modem_message")
- end
- senderID,_ = nil
- return message
- end
- function getOutput(side,id)
- message = textutils.serialize("getOutput",0,side,id)
- send(message)
- while senderID ~= id do
- _,_,_,senderID,message = os.pullEvent("modem_message")
- end
- senderID,_ = nil
- return message
- end
- function getAnalogOutput(side,id)
- message = textutils.serialize("getAnalogOutput",0,side,id)
- send(message)
- while senderID ~= id do
- _,_,_,senderID,message = os.pullEvent("modem_message")
- end
- senderID,_ = nil
- return message
- end
- function getBundledOutput(side,id)
- message = textutils.serialize("getBundledOutput",0,side,id)
- send(message)
- while senderID ~= id do
- _,_,_,senderID,message = os.pullEvent("modem_message")
- end
- senderID,_ = nil
- return message
- end
- function testBundledInput(num,side,id)
- message = textutils.serialize("testBundledInput",num,side,id)
- send(message)
- while senderID ~= id do
- _,_,_,senderID,message = os.pullEvent("modem_message")
- end
- senderID,_ = nil
- return message
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement