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

Autoplaying Jukebox Program Not Repeating The Disk Properly

Started by SteamPunkCherub, 26 July 2013 - 01:58 AM
SteamPunkCherub #1
Posted 26 July 2013 - 03:58 AM
I've been working on this code all day, its one of the first things I've programed in Lua (tho I have some knowledge of other languages). The program works nearly as intended excpet it tends to loop the disk too early.

here is a pastebin to the code: http://pastebin.com/u0d116nX

It seems to misbehave after the music disk has been restarted using 'P', my guess is that each time it is told to play it creates a new timer, and the extra timers are making it loop at the wrong times, but I've run out of ideas on how to fix it.
Lyqyd #2
Posted 26 July 2013 - 12:37 PM
Split into new topic.
SteamPunkCherub #3
Posted 26 July 2013 - 11:05 PM
I finaly solved it, seems kinda simple now.
I just took this if then statement

if input == "P" or loop then
	  timer = os.startTimer(time)
	  playing = true
	  disk.playAudio(ddisk)
	  loop = false
	elseif input == "S"then
	  timer = 0
	  time = 0
	  playing = false
	  disk.stopAudio(ddisk)
	end

and added a "input = "" line after "loop = false" and disk.stopAudio(ddisk)
derp

final code: http://pastebin.com/GKg3f2Dm
much sloppier than i'd like, having picked at it non-stop to figure this out lol
Edited on 26 July 2013 - 09:09 PM