Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function getDevices(deviceType) -- This function was taken from https://github.com/sandalle/minecraft_bigreactor_control and has been modified by https://github.com/Sanwi
- local deviceName = nil
- local deviceIndex = 1
- local deviceList, deviceNames = {}, {} -- Empty array, which grows as we need
- local peripheralList = peripheral.getNames() -- Get table of connected peripherals
- for peripheralIndex = 1, #peripheralList do -- Log every device found
- if (string.lower(peripheral.getType(peripheralList[peripheralIndex])) == deviceType) then -- Log devices found which match deviceType and which device index we give them
- deviceNames[deviceIndex] = peripheralList[peripheralIndex]
- deviceList[deviceIndex] = peripheral.wrap(peripheralList[peripheralIndex])
- deviceIndex = deviceIndex + 1
- end
- end -- for peripheralIndex = 1, #peripheralList do
- return deviceList, deviceNames
- end
- local function createFile(name,content)
- if fs.exists(name) then --if file exists
- return
- else
- file = fs.open(name, "w")
- file.write(content)
- file.flush()
- end
- end
- local function readFile(fileName)
- if fs.exists(fileName) then
- fileTable = {name=fileName,content=fs.open(fileName, "r").readAll()}
- cFile.close()
- return fileTable
- else
- return "File not found"
- end
- end
- local function listen(modem,channels)
- --Open channels
- for i=1, #channels do
- modem.open(channels[i])
- end
- --Listen
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- modem.closeAll()
- return event, modemSide, senderChannel, replyChannel, message, senderDistance
- end
- function main()
- local channels = {400,401,402}
- while true do
- write("> ")
- deviceList, deviceNames = getDevices("modem")
- local input = read();
- if input == "exit" or input == "bye" then
- print("Goodbye")
- error() -- Only temporary until I figure out how to properly terminate a program
- else
- modem.transmit(replyChannel,senderChannel,input)
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = listen(deviceList[1],channels)
- return message
- end
- write("\n")
- end
- end
- term.setTextColor(colors.yellow)
- write("Sulphur")
- term.setTextColor(colors.lightGray)
- write("Cloud")
- term.setTextColor(colors.white)
- print(" v. dev-0.0.1")
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement