Guest User

Table2

a guest
Jul 18th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. -----Manage-Colors-----
  2. local function AddOutput(sSide,...)
  3.  local c = colors.combine(rs.getBundledOutput(sSide),...)
  4.   rs.setBundledOutput(sSide,c)
  5. end
  6. local function RemoveOutput(sSide,...)
  7.   local c = colors.subtract(rs.getBundledOutput(sSide),...)
  8.   rs.setBundledOutput(sSide,c)
  9. end
  10. -------Table---------
  11. Table = {}
  12. Table[1]= {["on"] = false,["name"] = "Purple Lamp",["color"] = colors.purple}
  13. Table[2] = {["on"] = false,["name"] = "Green Lamp",["color"] = colors.red}
  14. Table[101] = {["on"] = false,["name"] = "Sprinkler 1",["color"] = colors.lime}
  15. Table[102] = {["on"] = false,["name"] = "Sprinkler 2",["color"] = colors.yellow}
  16. Table[103] = {["on"] = false,["name"] = "Sprinkler 3",["color"] = colors.brown}
  17. Table[104] = {["on"] = false,["name"] = "Sprinkler 4",["color"] = colors.white}
  18. all = colors.combine(colors.red,colors.yellow,colors.lime,colors.brown,colors.purple,colors.white)
  19. rs.setBundledOutput("top",all)
  20. --------functions--------------
  21. local function showtable()
  22. term.setCursorPos(1,1)
  23. term.clear()
  24.     for i , v in pairs(Table) do
  25.       c = Table[i]["on"]
  26.       local s = "off"
  27.         if c == true then
  28.         s = "on"
  29.         else
  30.              s = "off"
  31.         end
  32.       l = Table[i]["name"]
  33.       io.write(l)
  34.       Cursorx,CursorY = term.getCursorPos()
  35.       term.setCursorPos(14,CursorY)
  36.       io.write(s.."\n")
  37.     end
  38.  
  39.     term.setCursorBlink(true)
  40.     io.write("> ")
  41. end
  42. ----
  43. function test(thing)
  44. local t = string.lower(thing)
  45.  
  46. if string.find(t,"pu") then
  47. return 1
  48.  
  49. elseif string.find(t,"gr") then
  50. return 2
  51.  
  52. elseif string.find(t,"1") and string.find(t,"spri") then
  53. return 101
  54.  
  55. elseif string.find(t,"2") and string.find(t,"spri") then
  56. return 102
  57.  
  58. elseif string.find(t,"3") and string.find(t,"spri") then
  59. return 103
  60.  
  61. elseif string.find(t,"4") and string.find(t,"spri") then
  62. return 104
  63.  
  64. else
  65. return false
  66. end
  67. end
  68. ---------------------------
  69. while true do
  70. showtable()
  71. num = test(io.read())
  72. top = rs.getBundledOutput("top")
  73. if num then
  74. read = tonumber(num)
  75. tcolor = Table[read]["color"]
  76.   if colors.test(top,tcolor) == true then
  77.     Table[read]["on"] = true
  78.     RemoveOutput("top",tcolor)
  79.   elseif colors.test(top,tcolor) == false then
  80.     Table[read]["on"] = false
  81.     AddOutput("top",tcolor)
  82.   end
  83. end
  84. end
Advertisement
Add Comment
Please, Sign In to add comment