Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.wrap("left")
- rednet.open("bottom")
- mon.setTextScale(0.5)
- local stair = -1
- local newstair
- local masterd = 1
- local newstair = 0
- local elevator = 7
- button = {
- [1] = {x = 7; y = 5; active = false; name = "-1"},
- [2] = {x = 5; y = 5; active = true; name = " 0"},
- [3] = {x = 11; y = 5; active = true; name = "-2"},
- }
- function waitClick()
- event, a1, a2, a3 = os.pullEvent()
- if event == "rednet_message" then
- newstair = tonumber(a2)
- if newstair == stair then
- for i = 2,3 do button[i].active = true
- print(i.." : "..tostring(button[i].active))
- end
- button[1].active = false
- else
- for i = 2,3 do button[i].active = false
- print(i.." : "..tostring(button[i].active))
- end
- button[1].active = true
- end
- screen()
- elseif event == "monitor_touch" then
- local selectedButton = getButton(a2,a3)
- if selectedButton == nil then
- return
- end
- sleep(1.5)
- rednet.send(elevator, button[selectedButton].name)
- screen()
- end
- end
- function screen()
- mon.clear()
- mon.setCursorPos(5,1)
- mon.write("Etage " .. newstair)
- if newstair == stair then
- mon.setCursorPos(1,2)
- mon.write("~~~~~~~~~~~~~~~")
- for i = 3,8 do
- mon.setCursorPos(1,i)
- mon.write("|")
- mon.setCursorPos(15,i)
- mon.write("|")
- end
- mon.setCursorPos(1,9)
- mon.write("~~~~~~~~~~~~~~~")
- mon.setBackgroundColor(colors.gray)
- for i = 2,3 do
- mon.setCursorPos(button[i].x-2,button[i].y-1)
- mon.write(" ")
- mon.setCursorPos(button[i].x-2,button[i].y)
- mon.write(" "..button[i].name.." ")
- mon.setCursorPos(button[i].x-2,button[i].y+1)
- mon.write(" ")
- end
- mon.setBackgroundColor(colors.black)
- else
- mon.setCursorPos(1,2)
- mon.write("~~~~~~~~~~~~~~~")
- for i = 3,8 do
- mon.setCursorPos(1,i)
- mon.write("|")
- mon.setCursorPos(15,i)
- mon.write("|")
- end
- mon.setCursorPos(1,9)
- mon.write("~~~~~~~~~~~~~~~")
- mon.setBackgroundColor(colors.red)
- mon.setCursorPos(6,5)
- mon.write(" Call")
- mon.setBackgroundColor(colors.black)
- end
- end
- function getButton(xPos,yPos)
- for i=1,3 do
- if button[i].active == true then
- bxPos = button[i].x
- byPos = button[i].y
- xMax = bxPos + 2
- xMin = bxPos - 2
- yMax = byPos + 1
- yMin = byPos - 1
- if xPos >= xMin and xPos <= xMax and yPos >= yMin and yPos <= yMax then
- return i
- end
- end
- end
- end
- while true do
- name = ""
- waitClick()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement