Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Determine variables, tables, functions, APIs
- os.loadAPI("button")
- local modem = nil
- local monitor = nil
- local result = nil
- local greatestLength = 1
- local spawners = {}
- local sides = {"front", "back", "left", "right", "top", "bottom"}
- local default = 1
- local id = tonumber(os.getComputerID())
- local label = os.getComputerLabel()
- local function event(timeout)
- local result = {}
- local eventFunction = function()
- result = { os.pullEvent() }
- if result[1] == "monitor_touch" or result[1] == "modem_message" then
- returnValue = true
- end
- end
- parallel.waitForAny(function() sleep(timeout) end, eventFunction)
- if returnValue then return result end
- end
- --Determine which sides the peripherals are located
- for i=1, #sides do
- if peripheral.getType(sides[i]) == "modem" then
- modem = peripheral.wrap(sides[i])
- elseif peripheral.getType(sides[i]) == "monitor" then
- monitor = peripheral.wrap(sides[i])
- end
- end
- if modem == nil or monitor == nil then
- print("Modem/Monitor not found, please attach peripheral.")
- end
- --Open a channelto receive messages
- modem.open(default) modem.transmit(default, default, "ping")
- while true do
- --Reset some variables
- wireless = false
- touch = false
- --Wait for an event(button or wireless)
- result = { os.pullEvent() }
- if result[1] == "modem_message" then
- senderChannel = result[3]
- replyChannel = result[4]
- message = result[5]
- wireless = true
- elseif result[1] == "monitor_touch" then
- xTouch = result[3]
- yTouch = result[4]
- touch = true
- end
- if wireless then
- --If the event was a message,
- --react to message
- if string.find(message, "Spawner") ~= nil then
- local subtract = string.gsub(message, "Spawner ", '')
- spawners[subtract] = { channel = tonumber(replyChannel), status = false, link = false, name = tostring(subtract) }
- end
- --Send a message back to available computers
- for k,v in pairs(spawners) do
- if not v.link then
- modem.transmit(tonumber(v.channel), default, "loop")
- spawners[v.link] = true
- end
- end
- end
- if touch then
- --Touch, I remember, 'touch.'
- button.checkxy(xTouch, yTouch)
- end
- --monitor stuff
- for k,v in pairs(spawners) do
- if string.len(v.name) > greatestLength then
- greatestLength = string.len(v.name)
- end
- end
- xMon, yMon = monitor.getSize()
- possibleButtonRows = math.floor((xMon - 4)/(greatestLength + 4))
- possibleButtonColumns = math.floor((yMon - 3)/3)
- print(#spawners)
- button.heading("Spawner Control System")
- end
Advertisement
Add Comment
Please, Sign In to add comment