zilvar2k11

CC Redstone And Gate

Jul 3rd, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. local tArgs = {...}
  2.  
  3. if #tArgs ~= 1 then
  4.    print("Usage: andGate <sides>")
  5.    print("  -- the left of the screen is A, the screen is B")
  6.    print("  -- the right of the screen is C, the back is output")
  7.    print("  -- if sides is 1, the system will check A and B")
  8.    print("  -- if sides is 2, the system will check B and C")
  9.    print("  -- if sides is 3, the system will check A and C")
  10.    print("  -- if sides is 4, the system will check A, B, and C")
  11.    print("  -- all inputs must be true(active) for the output to be true")
  12.    return
  13. end
  14.  
  15. local sides = tonumber(tArgs[1])
  16.  
  17. if sides < 1 then
  18.   sides = 1
  19. elseif sides > 4 then
  20.   sides = 4
  21. end
  22.  
  23. local function testTwo(side1, side2)
  24.   if (((redstone.getInput(side1) == true) or (redstone.getBundledInput(side1) > 0)) and
  25.      ((redstone.getInput(side2) == true) or (redstone.getBundledInput(side2) > 0))) then
  26.        redstone.setOutput("back",true)
  27.        redstone.setBundledOutput("back",255)
  28.   else
  29.      redstone.setOutput("back",false)
  30.      redstone.setBundledOutput("back",0)
  31.   end
  32. end
  33.  
  34. while true do
  35.   if (sides == 1) then
  36.     testTwo("left","front")
  37.   end
  38.  
  39.   if (sides == 2) then
  40.     testTwo("right","front")
  41.   end
  42.  
  43.   if (sides == 3) then
  44.     testTwo("right","left")
  45.   end
  46.  
  47.   if (sides == 4) then
  48.     if (((redstone.getInput("left") == true) or (redstone.getBundledInput("left") > 0)) and
  49.        ((redstone.getInput("front") == true) or (redstone.getBundledInput("front") > 0)) and
  50.        ((redstone.getInput("right") == true) or (redstone.getBundledInput("right") > 0))) then
  51.          redstone.setOutput("back",true)
  52.          redstone.setBundledOutput("back",255)
  53.     else
  54.       redstone.setOutput("back",false)
  55.       redstone.setBundledOutput("back",0)
  56.     end
  57.   end
  58.  
  59.  
  60.   os.pullEvent("redstone")
  61.  
  62. end
Advertisement
Add Comment
Please, Sign In to add comment