Guest User

playSong.lua

a guest
May 28th, 2020
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. s = peripheral.wrap("top")
  2. volume = 2.0
  3. songName = "test.lua"
  4.  
  5. function playNote(instrument, note)
  6.     s.playNote(instrument, volume, tonumber(note))
  7. end
  8.  
  9. function wait(time)
  10.     sleep(tonumber(time)*0.05)
  11. end
  12.  
  13. function parse(str)
  14.     if(string.find(str, "delay:")) then
  15.         wait(string.sub(str,7))
  16.     else
  17.         instru_pre = string.match(str, ".*:")
  18.         print(instru_pre)
  19.         instru = string.sub(instru_pre, 1, string.len(instru_pre)-1)
  20.         note_pre = string.match(str, ":.*")
  21.         note = string.sub(note_pre, 2)
  22.         playNote(instru,note)
  23.     end
  24. end
  25.  
  26. function main()
  27.     song = fs.open(songName, "r")
  28.     x = song.readLine()
  29.     while x ~= nil do
  30.         parse(x)
  31.         x = song.readLine()
  32.     end
  33. end
  34.  
  35. main()
Advertisement
Add Comment
Please, Sign In to add comment