Advertisement
Selim_042

lampColorChanger

Apr 6th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.90 KB | None | 0 0
  1. // By Selim
  2. // Uses Computronics Colorful Lamps with ComputerCraft
  3.  
  4. peripheralType = "colorful"
  5. monitor = peripheral.find("monitor")
  6. periph = peripheral.getNames()
  7. running = true
  8.  
  9. function mysplit(inputstr, sep)
  10.   if sep == nil then
  11.     sep = "%s"
  12.   end
  13.   local t={} ; i=1
  14.   for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  15.     t[i] = str
  16.     i = i + 1
  17.   end
  18.   return t
  19. end
  20.  
  21. l = 1
  22. lamps = {}
  23. for i = 1, #periph do
  24.   type = mysplit(periph[i], "_")
  25.   if type[1] == peripheralType then
  26.     lamps[l] = peripheral.wrap(periph[i])
  27.     l = l + 1
  28.   end
  29. end
  30.  
  31. while running do
  32.   monitor.setTextScale(2)
  33.   monitor.print("What lamp color?")
  34.   in = read()
  35.   color = tonumber(in)
  36.   if type(color) == "number" then
  37.     for i = 1, #lamps do
  38.       lamps[i].setLampColor(color)
  39.     end
  40.   elseif in == "exit" then
  41.     running = false
  42.   else
  43.     print("Invalid entry")
  44.     sleep(2)
  45.   end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement