2 posts
Posted 19 April 2013 - 10:48 AM
So I have written simple disk player for term, and then decided to make it for the monitor. After few lines of codes I decided to test it and that's when I noticed it's not printing disk titles on the monitor.
mon = peripheral.wrap("right")
mon.clear()
mon.setCursorPos(1,1)
x,y = mon.getSize()
i = 1
for n,m in pairs(rs.getSides()) do
mon.setCursorPos(1,i)
mon.write(disk.getAudioTitle(m))
i = i + 2
end
Any suggestions why it's not printing?
1190 posts
Location
RHIT
Posted 19 April 2013 - 11:04 AM
Only thing I can imagine would be causing issues here is if there is in fact no music disk on any of the sides. Just as a test, try putting something inside of the mon.write other than disk.getAudioTitle and see if anything is printed. If not, then I'm not sure what's going on here. Is this your full code or is it just a snippet?
2 posts
Posted 19 April 2013 - 11:22 AM
Full code. I stopped writing more as soon as I realised it's not printing anything on screen. Yes, disk was present. I tried many time before instead of disk.getAudioTitle() just to put mon.write(m) and it works as intended. Once I replace it with disk.getAudioTitle(), same thing, blank. It works in terminal, so I don't get why it doesn't work on monitor…
173 posts
Posted 19 April 2013 - 03:21 PM
My only guess is because your going through all the sides, and when you get to a side without a disk it breaks. Also if that same code worked on terminal could brake now when tries to getAudioTitle of monitor instead of just nothing.
1190 posts
Location
RHIT
Posted 19 April 2013 - 03:28 PM
My only guess is because your going through all the sides, and when you get to a side without a disk it breaks. Also if that same code worked on terminal could brake now when tries to getAudioTitle of monitor instead of just nothing.
It shouldn't break when encountering a side without a disk, but in case it is you could try adding this:
mon.write(n..": ".. (disk.getAudioTitle(m) or "No disk")) --The or is what's important here: it just specifies that if disk.getAudioTitle returns false or nil, it should print "No disk" instead
173 posts
Posted 19 April 2013 - 04:23 PM
Ok so I ran some tests and I figured out what the problem is. the computer's write function just does nothing. The monitors write function on the other hand stops your program if you pass it nil. So to fix you can do what bubba suggests or this:
if disk.getAudioTitle(m) then
mon.write(getAudioTitle(m))
i = i+2
end
I would suggest this because now, instead of printing "no disk" it just prints valid titles. If you do want it to print "no disk" then I would suggest this:
mon.write(disk.getAudioTitle(m) or "No disk on "..m.." side.")