kamilosxd678

[MC-CC] Queue

Sep 27th, 2012
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. queue_crater_village = {}
  2.  
  3. sides = {}
  4. sides[1] = "left"  -- Input
  5. sides[2] = "right" -- Output
  6. sides[3] = "back"  -- Detectors
  7.  
  8. outputColors = colors.black
  9.  
  10. function push(list, value)
  11.  table.insert(list, 1, value)
  12. end
  13.  
  14. function pop(list)
  15.  last = table.getn(list)
  16.  value = list[last]
  17.  table.remove(list, last)
  18.  return value
  19. end
  20.  
  21. while true do
  22.  -- Inputs
  23.  if colors.test(rs.getBundledInput(sides[1]), colors.white) then
  24.   -- Wioska
  25.   push(queue_crater_village, false)
  26.  elseif colors.test(rs.getBundledInput(sides[1]), colors.orange) then
  27.   -- Krater
  28.   push(queue_crater_village, true)
  29.  end
  30.  -- Detectors
  31.  if colors.test(rs.getBundledInput(sides[3]), colors.white) then
  32.   crater = pop(queue_crater_village)
  33.   if not colors.test(outputColors, colors.white) then
  34.    outputColors = outputColors + colors.white
  35.   end
  36.   -- Wioska x Krater
  37.   if not crater then
  38.    outputColors = outputColors - colors.white
  39.   end
  40.  end
  41.  rs.setBundledOutput(sides[2], outputColors)
  42.  os.sleep(1)
  43. end
Advertisement
Add Comment
Please, Sign In to add comment