Advertisement
Guest User

wireless_redstone.lua

a guest
Nov 26th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1.  
  2. function P(name)
  3.   return component.proxy(component.list(name)())
  4. end
  5.  
  6. local redstone = P('redstone')
  7. local modem = P('modem')
  8. local sign = P('sign')
  9.  
  10. local PORT = 2001
  11. local REDSTONE_SIDE = 2 -- sides.back
  12.  
  13. function sum(...)
  14.   total = 0
  15.   for i,v in ipairs(arg) do
  16.     total = total + v
  17.   end
  18.   return total
  19. end
  20.  
  21. function sum_string(my_string)
  22.   return sum(string.byte(my_string, 1, -1))
  23. end
  24.  
  25. function beep_string(my_string)
  26.   tone = sum_string(my_string) % 1980
  27.   tone = tone + 20
  28.   computer.beep(tone)
  29. end
  30.  
  31.  
  32. modem.setWakeMessage('wake_wireless_redstone')
  33. modem.open(PORT)
  34.  
  35. -- Startup "chime"
  36. computer.beep(123)
  37. computer.beep(234)
  38. computer.beep(345)
  39.  
  40. while true do
  41.   local event, _, _, port, distance, message = computer.pullSignal()
  42.   if event == 'modem_message' then
  43.     label = sign.getValue()
  44.     beep_string(message)
  45.     if label == message then
  46.       beep_string(message)
  47.       os.sleep(1)
  48.       redstone.setOutput(REDSTONE_SIDE, 0)
  49.     end
  50.   end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement