Advertisement
Sv443

ComputerCraft Redstone XOR / XNOR Gate

Dec 28th, 2023
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | Gaming | 0 0
  1. -- Redstone input sides
  2. INPUT_A = "left"
  3. INPUT_B = "right"
  4.  
  5. -- Redstone output side
  6. OUTPUT = "back"
  7.  
  8. -- Set to true to turn this XOR gate into a XNOR gate
  9. OUTPUT_INVERTED = false
  10.  
  11. -- How often to check for changes, in seconds
  12. -- Has to be a multiple of 0.05 (1 game tick)
  13. CHECK_INTERVAL = 0.05
  14.  
  15. function run()
  16.     print("\n| XOR / XNOR gate by Sv443")
  17.     print("| https://github.com/Sv443/ComputerCraft-Projects\n")
  18.     local outVal
  19.     while true do
  20.         local a = redstone.getInput(INPUT_A)
  21.         local b = redstone.getInput(INPUT_B)
  22.  
  23.         if a and not b or not a and b then
  24.             outVal = not OUTPUT_INVERTED
  25.         else
  26.             outVal = OUTPUT_INVERTED
  27.         end
  28.  
  29.         redstone.setOutput(OUTPUT, outVal)
  30.         os.sleep(CHECK_INTERVAL)
  31.     end
  32. end
  33.  
  34. run()
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement