Advertisement
Guest User

Table

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