This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DestinedTick's profile picture

Advanced Monitor bugs out

Started by DestinedTick, 25 September 2016 - 09:11 AM
DestinedTick #1
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:

--# 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
 
Bomb Bloke #2
Posted 25 September 2016 - 01:29 PM
This line near the bottom:

peripheral.call("left","clear")

… wipes the whole display, setting it to the currently selected terminal background colour. If you want the buttons to be drawn over the top of that again, you'll need to call t:draw() again.

Looks like you may also want to change disk.stopAudio(p1) to disk.stopAudio(actDrv).
DestinedTick #3
Posted 25 September 2016 - 02:38 PM
Thank you so much for your help. This fixed it. +1