Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = { ... }
- local speaker = peripheral.find("speaker")
- local instrument = "pling"
- local volume = 1
- local silent = true
- local function setColor(color)
- if term.isColor() then
- term.setTextColor(color)
- end
- end
- local function errorMsg(message)
- setColor(colors.red)
- print(message)
- setColor(colors.white)
- end
- if #args == 0 then
- errorMsg("Usage: playsong (songfile.sng)")
- return
- end
- if args[2] == "v" then
- silent = false
- end
- local fileName = args[1]
- songFile = fs.open(fileName,"r")
- songList = textutils.unserialize(songFile.readAll())
- songFile.close()
- for i=1,#songList,1 do
- local songdata = songList[i]
- if type(songdata[1]) == "string" then
- if not silent then
- print("setting instrument to "..songdata[1])
- end
- instrument = songdata[1]
- volume = songdata[2]
- else
- if not silent then
- print("playing note at pitch "..songdata[1])
- end
- speaker.playNote(instrument,volume,songdata[1])
- sleep(songdata[2])
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement