Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("button")
- os.loadAPI("radar")
- local mon = peripheral.find("monitor")
- local xMax, yMax = mon.getSize()
- --#region
- -- data that needs to be asynced
- local roomAmount = 4
- local occupied = 0
- --#endregion
- local checkInBtn = "Check In"
- local checkOutBtn = "Check Out"
- local currentRoom = 0
- -- room number, player, isOccupied
- local rooms = {["1"] = "", ["2"] = "",
- ["3"] = "", ["4"] = ""}
- function printm(str, x, y)
- mon.setCursorPos(x, y)
- mon.clearLine()
- mon.write(str)
- end
- function fillButtons()
- -- xmin xmax, ymin, ymax
- button.setTable(checkInBtn, checkIn, 11, 20, 4, 12)
- button.setTable(checkOutBtn, checkOut, 22, 31, 4, 12)
- button.screen()
- end
- function drawText()
- printm("Rooms Available: ".. roomAmount - occupied, 2, 14)
- printm("Rooms Occupied: ".. occupied, 2, 15)
- end
- function getClosest()
- return radar.findClosest()
- end
- function getRoomAssignment()
- for key, obj in pairs(rooms) do
- print(key.. " "..tostring(obj))
- if obj == "" then
- rooms[key] = getClosest()
- currentRoom = key
- print(key)
- print("Room was assigned..".. key)
- return
- end
- end
- end
- function getClick()
- drawText()
- event, side, x, y = os.pullEvent("monitor_touch")
- button.checkxy(x, y)
- end
- -- check in function
- function checkIn()
- if occupied < roomAmount then
- button.flash(checkInBtn)
- print("Rooms are empty")
- occupied = occupied + 1
- getRoomAssignment()
- printm(getClosest() .." is assigned Room ".. currentRoom, 1, yMax)
- sleep(3)
- mon.clearLine()
- end
- end
- function checkOut()
- occupied = occupied - 1
- button.flash(checkOutBtn)
- print("Checking Out!")
- button.screen()
- end
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1, 1)
- button.heading("Hello World!")
- fillButtons()
- while true do
- getClick()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement