Advertisement
Guest User

Table2

a guest
Jul 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 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,["need"] = "pur",["neednum"] = false}
  13. Table[2] = {["on"] = false,["name"] = "Green Lamp",["color"] = colors.red,["need"] = "gre",["neednum"] = false}
  14. Table[101] = {["on"] = false,["name"] = "Sprinkler 1",["color"] = colors.lime,["need"] = "spri",["neednum"] = 1}
  15. Table[102] = {["on"] = false,["name"] = "Sprinkler 2",["color"] = colors.yellow,["need"] = "spri",["neednum"] = 2}
  16. Table[103] = {["on"] = false,["name"] = "Sprinkler 3",["color"] = colors.brown,["need"] = "spri",["neednum"] = 3}
  17. Table[104] = {["on"] = false,["name"] = "Sprinkler 4",["color"] = colors.white,["need"] = "spri",["neednum"] = 4}
  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. for i , v in pairs(Table) do
  47. c = tonumber(string.match(t,"%d+"))
  48. if Table[i]["neednum"] ~= false then
  49. print("read "..c)
  50. print("Tab "..Table[i]["neednum"])
  51. if string.find(t,Table[i]["need"]) == true and Table[i]["neednum"] == c then
  52. print("with num"..i)
  53. return i
  54. end
  55.  
  56.  
  57. else
  58.  
  59. if string.find(t,Table[i]["need"]) then
  60. print("no num"..i)
  61. return i
  62. end
  63.  
  64. end
  65. end
  66.  
  67.  
  68.  
  69. --if string.find(t,"pu") then
  70. --return 1
  71.  
  72. --elseif string.find(t,"gr") then
  73. --return 2
  74.  
  75. --elseif string.find(t,"1") then
  76. --return 101
  77.  
  78. --elseif string.find(t,"2") and string.find(t,"spri") then
  79. --return 102
  80.  
  81. --elseif string.find(t,"3") then
  82. --return 103
  83.  
  84. --elseif string.find(t,"4") then
  85. --return 104
  86.  
  87. --else
  88. --return false
  89. --end
  90. end
  91. ---------------------------
  92. while true do
  93. showtable()
  94. num = test(io.read())
  95. top = rs.getBundledOutput("top")
  96. print(c)
  97. print(Table[102]["neednum"])
  98. os.sleep(4)
  99. if num then
  100. read = tonumber(num)
  101. tcolor = Table[read]["color"]
  102.   if colors.test(top,tcolor) == true then
  103.     Table[read]["on"] = true
  104.     RemoveOutput("top",tcolor)
  105.   elseif colors.test(top,tcolor) == false then
  106.     Table[read]["on"] = false
  107.     AddOutput("top",tcolor)
  108.   end
  109. end
  110. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement