Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local SIDES = {"front", "left", "back", "right", "top", "bottom"}
- local listenChannel = tonumber(tArgs[2])
- local modem
- local peripherals
- local redstoneSide = tArgs[1]
- local defaultState = tArgs[3]
- function inputCheck()
- if isSide(redstoneSide) ~= true then
- print("Invalid side")
- return
- end
- if type(listenChannel) ~= "number" then
- print("Channel must be a number")
- return
- end
- if defaultState == "true" then
- redstone.setOutput(redstoneSide, true)
- end
- end
- function isSide(side)
- for i=1,6 do
- if side == SIDES[i] then
- return true
- end
- end
- return false
- end
- function modemSetup(side)
- print("Modem is setting up...")
- modem = peripheral.wrap(side)
- modem.open(listenChannel) -- Open channel 3 so that we can listen on it
- print("Modem is on the "..side.." side of the computer...")
- end
- function findPeripherals()
- local tempPeripherals = {}
- for i=1,6 do
- if peripheral.isPresent(SIDES[i]) == true then
- local type = peripheral.getType(SIDES[i])
- tempPeripherals[type] = {side = SIDES[i]}
- if type == "modem" then
- modemSetup(tempPeripherals.modem.side)
- end
- end
- end
- return tempPeripherals
- end
- inputCheck()
- peripherals = findPeripherals()
- while true do
- print("Looping, hold Ctrl+t to exit the program...")
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if (message ~= "on") and (message ~= "off") then
- modem.transmit(1, listenChannel, false)
- else
- if message == "on" then
- redstone.setOutput(redstoneSide, true)
- else
- redstone.setOutput(redstoneSide, false)
- end
- end
- end
- print("Goodbye...")
Add Comment
Please, Sign In to add comment