This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
M4sh3dP0t4t03's profile picture

RedGates 1.2.1 - easy to make, compact redstone gates for you

Started by M4sh3dP0t4t03, 14 April 2013 - 10:30 PM
M4sh3dP0t4t03 #1
Posted 15 April 2013 - 12:30 AM
I made a simple program for computers that is able to act like some kinds of redstone gates.

You can get it with:
pastebin get 2g4pAN2U RedGates

Features:
Spoiler-7 Gates: NOT-Gate, AND-Gate, NAND-Gate, OR-Gate, Redstone clock, XOR-Gate, XNOR-Gate, Randomizer
-wireless transmission of redstone signals
Screenshots(outdated):
Spoiler
changelog:
Spoiler1.01
-you can select sides now
1.1
-added wireless transmission
-exit programs with tab
1.2
-added T-Flip-Flop
-using os.pullEvent() to make it more efficient
1.2.1
-added Randomizer
-made code a little bit more efficient

Upcoming features:
-more gates
-(maybe in the future) combine gates (not sure if i am good enough in lua to do that)
-possibility to add own gates in the program
-maybe synchronized clocks over rednet
-simulate inputs

If you find bugs or have tips for me to do this better feel free to comment :)/>
FuuuAInfiniteLoop(F.A.I.L) #2
Posted 15 April 2013 - 02:48 AM
There are 16 gates and you can edit it to work with redstone, top and bottom for the inputs and the others for a binary selector of what gate to use
M4sh3dP0t4t03 #3
Posted 15 April 2013 - 03:11 AM
There are 16 gates and you can edit it to work with redstone, top and bottom for the inputs and the others for a binary selector of what gate to use
and where should the outputs be?
Symmetryc #4
Posted 15 April 2013 - 03:32 AM
You might want to make it so that you can set where the inputs/outputs are, but overall, nice program!
M4sh3dP0t4t03 #5
Posted 15 April 2013 - 03:35 AM
You might want to make it so that you can set where the inputs/outputs are, but overall, nice program!
i am working on that

Edit: impleted it in 1.01
Edit 2: does anyone know how to make the program quit if you press a key? i tried it with some of the code in the tutorials on the wiki, but then it did nothing anymore until i pressed a key
jesusthekiller #6
Posted 15 April 2013 - 05:53 AM
-snippy snip-
Edit 2: does anyone know how to make the program quit if you press a key? i tried it with some of the code in the tutorials on the wiki, but then it did nothing anymore until i pressed a key

You need to run your program in parallel (waitForAny) with key detection.

Example:


function f1()
  while true do
    print("Lol, i'm runnin\'")
    sleep(1)
  end
  return
end

function f2()
  e = nil
  while e ~= "key" do
    e = os.pullEvent("key")
  end
  return
end

parallel.waitForAny(f1, f2)
return
M4sh3dP0t4t03 #7
Posted 15 April 2013 - 06:02 AM
Thanks for the help! I will use that in a new version that I will make tomorrow if I have time for that
M4sh3dP0t4t03 #8
Posted 16 April 2013 - 06:23 AM
hello, i just made an update with wireless redstone, but its crashing every time i tried to use it. I dont know very much about rednet so could you help me out with this, please?
The code of the beta version:
Spoiler

function wirelesssend(...)
write("Modem side:")
modemside = io.read()
rednet.open(modemside)
write("ID of receiver:")
receiverid = io.read()
write("Input side:")
inputside = io.read()
while true do
  redstoneinput = redstone.getInput(inputside)
  if redstoneinput == true then
   rednet.send(receiverid, 1)
  elseif redstoneinput == false then
   rednet.send(receiverid, 0)
  end
  sleep(0.1)
end
end
function wirelessreceive(...)
write("Modem side:")
modemside = io.read()
rednet.open(modemside)
write("Output side:")
Outputside = io.read()
while true do
  message = rednet.receive(10)
  if message == 1 then
   redstone.setOutput(Outputside, true)
  elseif message == 0 then
   redstone.setOutput(Outputside, false)
  end
  sleep(0.1)
end
end
function waitforkey()
	while true do
		local sEvent, param = os.pullEvent("key")
		if sEvent == "key" then
			if param == 15 then
				redstone.setOutput("right", false)
				redstone.setOutput("left", false)
				redstone.setOutput("top", false)
				redstone.setOutput("bottom", false)
				redstone.setOutput("front", false)
				redstone.setOutput("back", false)
				break
			end
		end
	end
end

function RedClock(...)
print("RedClock")
write("Ticks:")
clockspeed = io.read()
clockspeedm = tonumber(clockspeed)
clockspeedm = clockspeedm/10
write("Side:")
side = io.read()
while true do
  redstone.setOutput(side, true)
  sleep(clockspeedm/2)
  redstone.setOutput(side, false)
  sleep(clockspeedm/2)
end
end
function AndGate(...)
print("AndGate")
write("Side of input a:")
sidea = io.read()
write("Side of input b:")
sideb = io.read()
write("Output Side:")
sidec = io.read()
while true do
  rightredstone = redstone.getInput(sidea)
  leftredstone = redstone.getInput(sideb)
  if rightredstone == true and leftredstone == true then
   redstone.setOutput(sidec, true)
  else
   redstone.setOutput(sidec, false)
  end
  sleep(0.1)
end
end
function OrGate(...)
print("OrGate")
write("Side of input a:")
sidea = io.read()
write("Side of input b:")
sideb = io.read()
write("Output Side:")
sidec = io.read()
while true do
  rightredstone = redstone.getInput(sidea)
  leftredstone = redstone.getInput(sideb)
  if rightredstone == true or leftredstone == true then
   redstone.setOutput(sidec, true)
  else
   redstone.setOutput(sidec, false)
  end
  sleep(0.1)
end
end
function XorGate(...)
print("XorGate")
write("Side of input a:")
sidea = io.read()
write("Side of input b:")
sideb = io.read()
write("Output Side:")
sidec = io.read()
while true do
  rightredstone = redstone.getInput(sidea)
  leftredstone = redstone.getInput(sideb)
  if rightredstone == true and leftredstone == false then
   redstone.setOutput(sidec, true)
  elseif rightredstone == false and leftredstone == true then
   redstone.setOutput(sidec, true)
  else
   redstone.setOutput(sidec, false)
  end
  sleep(0.1)
end
end
function NotGate(...)
print("NotGate")
write("Input Side:")
sidea = io.read()
write("Output Side:")
sideb = io.read()
while true do
  frontredstone = redstone.getInput(sidea)
  if frontredstone == false then
   redstone.setOutput(sideb, true)
  else
   redstone.setOutput(sideb, false)
  end
  sleep(0.1)
end
end
function NandGate(...)
print("NandGate")
write("Side of input a:")
sidea = io.read()
write("Side of input b:")
sideb = io.read()
write("Output Side:")
sidec = io.read()
while true do
  rightredstone = redstone.getInput(sidea)
  leftredstone = redstone.getInput(sideb)
  if rightredstone == false and leftredstone == false then
   redstone.setOutput(sidec, true)
  else
   redstone.setOutput(sidec, false)
  end
  sleep(0.1)
end
end
function XnorGate(...)
print("XnorGate")
write("Side of input a:")
sidea = io.read()
write("Side of input b:")
sideb = io.read()
write("Output Side:")
sidec = io.read()
while true do
  rightredstone = redstone.getInput(sidea)
  leftredstone = redstone.getInput(sideb)
  if rightredstone == true and leftredstone == true then
   redstone.setOutput(sidec, true)
  elseif rightredstone == false and leftredstone == false then
   redstone.setOutput(sidec, true)
  else
   redstone.setOutput(sidec, false)
  end
  sleep(0.1)
end
end
function TFlipFlop(...)
print("NotGate")
write("Input Side:")
sidea = io.read()
write("Output Side:")
sideb = io.read()
On = false
while true do
  redstoneinput = redstone.getInput(sidea)
  if redstoneinput == true then
   if On == false then
	redstone.setOutput(sideb, true)
	On = true
   elseif On == true then
	redstone.setOutput(sideb, false)
	On = false
   end
  end
  sleep(0.1)
end
end
function ChooseGate(...)
print("1=NotGate 2=AndGate 3=NandGate 4=OrGate 5=RedClock 6=XorGate 7=XnorGate")
Gate = io.read()
if Gate == "1" then
  parallel.waitForAny(NotGate, waitforkey)
elseif Gate == "2" then
  parallel.waitForAny(AndGate, waitforkey)
elseif Gate == "3" then
  parallel.waitForAny(NandGate, waitforkey)
elseif Gate == "4" then
  parallel.waitForAny(OrGate, waitforkey)
elseif Gate == "5" then
  parallel.waitForAny(RedClock, waitforkey)
elseif Gate == "6" then
  parallel.waitForAny(XorGate, waitforkey)
elseif Gate == "7" then
  parallel.waitForAny(XnorGate, waitforkey)
elseif Gate == "8" then
  parallel.waitForAny(TFlipFlop, waitforkey)
elseif Gate == "9" then
  parallel.waitForAny(wirelessreceive, waitforkey)
elseif Gate == "10" then
  parallel.waitForAny(wirelesssend, waitforkey)
end
end
print("RedGates 1.01")
ChooseGate()
edit : i have figured out what i did wrong and fixed it
edit 2: update 1.1 is out now, which contains this
Spongy141 #9
Posted 22 April 2013 - 04:53 PM
Seems cool
FuuuAInfiniteLoop(F.A.I.L) #10
Posted 11 May 2013 - 12:20 PM
with 16 options, you can use 4 wires for the options nad 2 for the redstone inputs and when the inputs are off, output the result