Advertisement
Guest User

Table2

a guest
Jul 17th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. -----Functions-----
  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. ----------------------
  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.    
  33.     l = Table[i]["name"]
  34.     io.write(l)
  35.     Cursorx,CursorY = term.getCursorPos()
  36.  
  37.     term.setCursorPos(14,CursorY)
  38.  
  39.     io.write(s.."\n")
  40.  
  41.     end
  42.     term.setCursorBlink(true)
  43.     io.write("> ")
  44. end
  45. ---------------------------
  46. function test(thing)
  47. local t = string.lower(thing)
  48.  
  49. if string.find(t,"pu") then
  50. return 1
  51.  
  52. elseif string.find(t,"gr") then
  53. return 2
  54.  
  55. elseif string.find(t,"1") then
  56. return 101
  57.  
  58. elseif string.find(t,"2") then
  59. return 102
  60.  
  61. elseif string.find(t,"3") then
  62. return 103
  63.  
  64. elseif string.find(t,"4") then
  65. return 104
  66.  
  67. else
  68. return false
  69. end
  70. end
  71. ---------------------------
  72. while true do
  73. showtable()
  74. read = test(io.read())
  75.  
  76. if read then
  77. tcolor = Table[read]["color"]
  78.     if colors.test("top",tcolor) == true then
  79.     Table[read]["on"] = true
  80.     RemoveOutput("top",tcolor)
  81.   elseif colors.test("top",tcolor) == false then
  82.     Table[read]["on"] = false
  83.     AddOutput("top",tcolor)
  84.   end
  85. end
  86. read = false
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement