Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local utils = require 'itsjstnutils'
- local w, h = term.getSize()
- local buttons = {}
- local function showButtons()
- utils.terminal.resetTerminal("Elevator Controls", nil)
- utils.pages.drawButtons(buttons, {})
- end
- local function showError()
- utils.terminal.resetTerminal("Elevator Controls", "Error")
- utils.terminal.safeWrite("Failed to communicate the specified command.", colors.red, true, true)
- sleep(3)
- showButtons()
- end
- local function showSuccess(message)
- utils.terminal.resetTerminal("Elevator Controls", "Success")
- utils.terminal.safeWrite(message, colors.green, true, true)
- sleep(3)
- showButtons()
- end
- buttons = {
- utils.types.PageButton(
- "raise",
- true,
- "Raise Lift",
- nil,
- (h / 2) - 1,
- true,
- colors.blue,
- function()
- local target = rednet.lookup("elev_op", "server")
- local response = utils.rednet.sendRednetRequest(target, {
- type = "raise"
- }, "elev_op", 10)
- if response.success then
- showSuccess("The elevator is now rising.")
- else
- showError()
- end
- end
- ),
- utils.types.PageButton(
- "lower",
- true,
- "Lower Lift",
- nil,
- (h / 2) + 1,
- true,
- colors.red,
- function()
- local target = rednet.lookup("elev_op", "server")
- local response = utils.rednet.sendRednetRequest(target, {
- type = "lower"
- }, "elev_op", 10)
- if response.success then
- showSuccess("The elevator is now lowering.")
- else
- showError()
- end
- end
- )
- }
- peripheral.find("modem", rednet.open)
- showButtons()
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- for i, v in ipairs(buttons) do
- local pos = v.getPosition()
- if pos.y == y and pos.startX <= x and pos.endX >= x then
- v.onClick()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement