Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function toggleLight(name)
- for i=1, #buttons do
- if buttons[i][1] == name then
- if buttons[i][2] then
- color = buttons[i][2]
- bundleAPI.toggle(bundleLoc, color)
- end
- end
- end
- end
- os.loadAPI("touchPoint")
- os.loadAPI("bundleAPI")
- if monitorLoc == nil then
- error("No monitor side has been defined")
- os.exit()
- end
- local monitor = peripheral.wrap(monitorLoc)
- if not peripheral.getType(monitorLoc) == "monitor" then
- error("the monitor isn't on the specified side")
- os.exit()
- end
- local w, h = monitor.getSize()
- print([[Size (w): ]]..w)
- print([[Size (h): ]]..h)
- local columnW = 12
- local rowW = 2
- local currentColumn = 2
- local currentRow = 2
- local t = touchPoint.new(monitorLoc)
- for i=1, #buttons do
- print([[Button: ]]..buttons[i][1]..[[ Type: ]]..tostring(buttons[i][3]))
- local Inactive
- local Active
- if buttons[i][3] then
- Inactive = colors.lime
- Active = colors.red
- bundleAPI.toggle(bundleLoc, buttons[i][2])
- else
- Inactive = colors.red
- Active = colors.lime
- end
- t:add(buttons[i][1], nil, currentColumn, currentRow, currentColumn + columnW, currentRow + rowW, Inactive, Active)
- if currentColumn == 2 then
- currentColumn = 16
- else
- currentColumn = 2
- currentRow = currentRow + rowW + 2
- end
- end
- t:draw()
- while true do
- local event, p1 = t:handleEvents(os.pullEvent())
- if event == "button_click" then
- toggleLight(p1)
- t:toggleButton(p1)
- print([[Button ]] ..p1.. [[ was pushed]])
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement