Posted 25 September 2016 - 11:11 AM
I have a script that allows for music discs to be selected and played via an advanced monitor and disk drives.
When clicking a button the music will start but the monitor will then become a full screen of red. The issue temporarily disappears when clicking the location of another button but will always return after about a second.
Here is the script in question:
When clicking a button the music will start but the monitor will then become a full screen of red. The issue temporarily disappears when clicking the location of another button but will always return after about a second.
Here is the script in question:
--# Load third-pary APIs
os.loadAPI("touchpoint")
--# Intialize all APIs and varibles
local t = touchpoint.new("left")
local wireless = peripheral.wrap("right")
actDrv = 0
--# Add buttons
--# First Row
t:add("drive_0", nil, 2, 2, 10, 5, colors.red, colors.lime)
t:add("drive_1", nil, 12, 2, 20, 5, colors.red, colors.lime)
t:add("drive_2", nil, 22, 2, 30, 5, colors.red, colors.lime)
t:add("drive_3", nil, 32, 2, 40, 5, colors.red, colors.lime)
t:add("drive_4", nil, 42, 2, 50, 5, colors.red, colors.lime)
--# Second Row
t:add("drive_5", nil, 2, 7, 10, 10, colors.red, colors.lime)
t:add("drive_6", nil, 12, 7, 20, 10, colors.red, colors.lime)
t:add("drive_7", nil, 22, 7, 30, 10, colors.red, colors.lime)
t:add("drive_8", nil, 32, 7, 40, 10, colors.red, colors.lime)
t:add("drive_9", nil, 42, 7, 50, 10, colors.red, colors.lime)
--# Third Row
t:add("drive_10", nil, 2, 12, 10, 15, colors.red, colors.lime)
t:add("drive_11", nil, 12, 12, 20, 15, colors.red, colors.lime)
--# This button should stop all audio
t:add("Stop", nil, 45, 23, 50, 26, colors.red, colors.lime)
t:draw()
while true do
--# handleEvents will convert monitor_touch events to button_click if it was on a button
local event, p1 = t:handleEvents(os.pullEvent())
if event == "button_click" then
t:flash(p1)
if p1 == "Stop" then
if actDrv == 0 then
peripheral.call("left","write","NOTHING PLAYING")
os.sleep (3)
peripheral.call("left","clear")
else
disk.stopAudio(p1)
peripheral.call("left","write","Stoping Audio")
actDrv = 0
os.sleep(3)
peripheral.call("left","clear")
end
else
actDrv = p1
disk.playAudio(p1)
peripheral.call("left","write", disk.getAudioTitle(p1))
os.sleep(3)
peripheral.call("left","clear")
end
end
end