Advertisement
TylerB

Radio controller

Aug 22nd, 2014
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. local args = {...}
  2. local side = "top"
  3.  
  4. if not args[1] then
  5.     local str = "OFF"
  6.     local vol = redstone.getAnalogOutput(side)
  7.  
  8.     if vol ~= 0 then str = "ON" end
  9.    
  10.     print("Radio is currently "..str..".")
  11.     print("Volume is "..vol.." / 15.")
  12.     print("\n")
  13.     print("Usage: radio < on / off / volume >")
  14.     print("Volume can be an integer from 1 to 15. Use 0 to turn off the radio.")
  15.     return
  16. end
  17.  
  18. if args[1] == "on" then
  19.     if redstone.getAnalogOutput(side) ~= 0 then
  20.         print("The radio is already on.")
  21.     end
  22.    
  23.     io.write("What volume? (1 - 15): ")
  24.     local vol = io.read()
  25.    
  26.     os.run({}, shell.getRunningProgram(), vol)
  27.    
  28.     return
  29. elseif args[1] == "off" then
  30.     redstone.setAnalogOutput(side,0)
  31.     print("Turning radio off. Goodbye!")
  32.     return
  33. else
  34.   local vol = tonumber(args[1])
  35.  
  36.   if not vol or vol ~= math.floor(vol) then
  37.       print("Please provide an integer.")
  38.       return
  39.   end
  40.  
  41.   vol = math.floor(vol)
  42.  
  43.   if vol < 1 then
  44.       os.run({}, shell.getRunningProgram(), "off")
  45.       return
  46.   end
  47.  
  48.   if vol > 15 then
  49.       print("Volume is out of range. Please provide an integer below 16.")
  50.       return
  51.   end
  52.  
  53.   print("Setting volume to "..vol.." / 15.")
  54.   redstone.setAnalogOutput(side, vol)
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement