zilvar2k11

CC Redstone XOR Gate

Jul 9th, 2013
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. local tArgs = {...}
  2.  
  3. if #tArgs ~= 1 then
  4.    print("Usage: xorGate <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 function testSide(side)
  16.    return ( (redstone.getInput(side)) or (redstone.getBundledInput(side) >0) )
  17.  
  18. end
  19.  
  20. local sides = tonumber(tArgs[1])
  21.  
  22. if sides < 1 then
  23.   sides = 1
  24. elseif sides > 4 then
  25.   sides = 4
  26. end
  27.  
  28. while true do
  29.  
  30.    if ( sides == 1 ) then
  31.      if ( (testSide("left") and not testSide("front")) or (not testSide("left") and testSide("front")) ) then
  32.        redstone.setOutput("back",true)
  33.        redstone.setBundledOutput("back",255)
  34.      end
  35.    elseif ( sides == 2 ) then
  36.      if ( (testSide("right") and not testSide("front")) or (not testSide("right") and testSide("front")) ) then
  37.        redstone.setOutput("back",true)
  38.        redstone.setBundledOutput("back",255)
  39.      end
  40.    elseif ( sides == 3 ) then
  41.      if ( (testSide("right") and not testSide("left")) or (not testSide("right") and testSide("left")) ) then
  42.        redstone.setOutput("back",true)
  43.        redstone.setBundledOutput("back",255)
  44.      end
  45.    elseif ( sides == 4 ) then
  46.      if ( (testSide("right") and not testSide("front") and not testSide("left")) or
  47.           (not testSide("right") and testSide("front") and not testSide("left")) or
  48.           (not testSide("right") and not testSide("front") and testSide("left")) then          
  49.        redstone.setOutput("back",true)
  50.        redstone.setBundledOutput("back",255)
  51.      end
  52.    else
  53.        redstone.setOutput("back",false)
  54.        redstone.setBundledOutput("back",0)
  55.    end
  56.    os.pullEvent("redstone")
  57. end
Advertisement
Add Comment
Please, Sign In to add comment