Guest User

Untitled

a guest
Aug 28th, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. local side = "back"
  2.  
  3. function allOff()
  4.   rs.setBundledOutput(side, 0)
  5. end
  6.  
  7. function set(color, state)
  8.   --# if it exists in the colors table use that colour
  9.   if colors[color] or colours[color] then
  10.     color = colors[color] or colours[color]
  11.   --# if it wasn't in the table, is not a number, and is not withing the color range, error!
  12.   elseif not (type(colors) == "number" and colors >= 0 and colors <= 65535) then
  13.     --# level of 3 here so the finger doesn't get pointed at our functions
  14.     error("Invalid colour supplied: Expected color got, "..tostring(color), 3)
  15.   end
  16.  
  17.   local func = state and colors.combine or colors.subtract
  18.   rs.setBundledOutput(side, func(rs.getBundledOutput(side), color))
  19. end
  20.  
  21. --[[
  22. calling this `get` is a little confusing, because it's not a get, it's a test this would be a getter:
  23. function get()
  24.   return rs.getBundledOutput(side)
  25. end
  26. --]]
  27. function get(color)
  28.   --# if it exists in the colors table use that colour
  29.   if colors[color] or colours[color] then
  30.     color = colors[color] or colours[color]
  31.   --# if it wasn't in the table, is not a number, and is not withing the color range, error!
  32.   elseif not (type(colors) == "number" and colors >= 0 and colors <= 65535) then
  33.     --# level of 3 here so the finger doesn't get pointed at our functions
  34.     error("Invalid colour supplied: Expected color got, "..tostring(color), 3)
  35.   end
  36.   return rs.testBundledInput(side, color)
  37. end
  38.  
  39. function toggle(color)
  40.   --# we should localise variables so they cannot be accessed by other programs, also renamed function call to test, to reflect above change
  41.   local cstate = test(color)
  42.   --# not cstate is the same as that if else statement, except more compact... not true == false just like not false == true
  43.   set(not cstate)
  44. end
  45.  
  46. function setside(s)
  47.   side = s
  48. end
Advertisement
Add Comment
Please, Sign In to add comment