Advertisement
Guest User

groovy_client.lua

a guest
Apr 5th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.78 KB | None | 0 0
  1. local function split (inputstr, sep)
  2.     if sep == nil then
  3.             sep = "%s"
  4.     end
  5.     local t={}
  6.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  7.             table.insert(t, str)
  8.     end
  9.     return t
  10. end
  11.  
  12. local modemSide, speakerSide = ...
  13.  
  14. local listenId = nil
  15.  
  16. rednet.open(modemSide)
  17. local speaker = peripheral.wrap(speakerSide)
  18.  
  19. while true do
  20.     senderId, message, distance, protocol = rednet.receive()
  21.    
  22.     params = split(message, ",")
  23.     cmd = params[1]
  24.    
  25.     if listenId == senderId and cmd == "groovy_play" then
  26.         speaker.playNote(params[2], tonumber(params[3]), tonumber(params[4]))
  27.     end
  28.  
  29.     if cmd == "groovy_start" then
  30.         listenId = senderId
  31.     elseif cmd == "groovy_stop" then
  32.         listenId = nil
  33.     end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement