Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- NoteBlock Song Player
- -- by MysticT
- -- load the nb and nbs apis
- if not nb then
- os.loadAPI("nb")
- if not nb then
- print("Couldn't load nb api. Check if you installed it correctly.")
- return
- end
- end
- if not nbs then
- os.loadAPI("nbs")
- if not nbs then
- print("Error loading nbs api. Check you installed it correctly.")
- return
- end
- end
- -- detect a modem and connect
- local function connect()
- for _,s in ipairs(rs.getSides()) do
- if peripheral.isPresent(s) and peripheral.getType(s) == "modem" then
- rednet.open(s)
- return true
- end
- end
- return false
- end
- -- try to connect to rednet
- if not connect() then
- print("No modem found")
- return
- end
- -- load and play an nbs file
- local function playFile(sPath)
- local tSong, err = nbs.load(sPath)
- if tSong then
- print("Playing: ", tSong.name, " - by ", tSong.author)
- if tSong.original_author ~= "" then
- print("Original Author: ", tSong.original_author)
- end
- print("Lenght: ", tSong.lenght)
- nb.playSong(tSong)
- return true
- end
- return false, err
- end
- -- Start Program
- -- get arguments
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print("Usage: nbsplay <file>")
- return
- end
- -- play the file
- local ok, err = playFile(tArgs[1])
- if not ok then
- return false, err
- end
Advertisement
Add Comment
Please, Sign In to add comment