Advertisement
Guest User

startup

a guest
May 26th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. os.startTimer(5)
  2. local radios = {}
  3. local function isRadio(msg)
  4.   if type(msg) ~= "table" then
  5.     return false
  6.   end
  7.   if msg.sType ~= "radio" then
  8.     return false
  9.   end
  10.   return true
  11. end
  12.  
  13. print("Scanning for online radio stations...")
  14. while true do
  15.   local tEvent = {os.pullEvent()}
  16.   if isRadio(tEvent[3]) then
  17.     radios[tEvent[3].sChannel] = tEvent[3].sChannel
  18.   end
  19.   if tEvent[1] == "timer" then
  20.     break
  21.   end
  22. end
  23. i = 0
  24. for k,v in pairs(radios) do
  25.   i = i + 1
  26.   print(i..": "..v)
  27. end
  28. write("Connect to: ")
  29. local chan = read()
  30.  
  31. function updateTime()
  32.   if cont.cur ~= ocur then
  33.     ges = cont.all
  34.     cur = cont.cur
  35.     allm = math.floor(ges/60)
  36.     alls = ges%60
  37.     curm = math.floor(cur/60)
  38.     curs = cur%60
  39.     text = string.format("%2i:%2i",curm,curs):gsub(" ","0").." / "..string.format("%2i:%2i",allm,alls):gsub(" ","0").." - "..cont.name
  40.     x,y = term.getCursorPos()
  41.     term.setCursorPos(1,y)
  42.     term.clearLine()
  43.     term.write(text)
  44.     ocur = cur
  45.   end
  46. end
  47. ocur = -1
  48. block = peripheral.find("iron_note")
  49. while true do
  50.   e = {os.pullEvent("bitnet_message")}
  51.   msg = e[3]
  52.   if msg.sType == "radio" and msg.sChannel == chan then
  53.     cont = msg.tMessage
  54.     updateTime()
  55.     for i,v in pairs(cont.notes) do
  56.       pcall(function() block.playNote(v.inst,v.pitch) end)
  57.     end
  58.   end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement