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

trying to create a t-flip-flop program

Started by sgtotaku, 03 January 2014 - 08:30 PM
sgtotaku #1
Posted 03 January 2014 - 09:30 PM
In trying to automate a TinkersConstruct foundry through a ComputerCraft program, I have started by attempting to create a t flip flop function that will also display on a monitor the status of active or inactive. For some reason, when running the program, i get an error:
tflip:5: expected string, number
tflip is the name of the program. I am using rednet cables to seperate the redstone signal colors. I have managed to get the program to display the "active" status on the monitor, and output the signal over the correct color, however, it does not disable the signal.

this is just the first part in the larger goal of automating the foundry, with multiple smelteries, and various required redstone signals. Since i just started to learn Lua, i'm attempting this piece by peice.

here's the code as it currently stands:
os.pullEvent("redstone")
while true do
	 if redstone.testBundledInput("left", colors.white) then
		  if redstone.testBundledInput("back", colors.orange) then
			   redstone.setBundledOutput("back", colors.orange, false)
			   peripheral.wrap("right").write("inactive")
		  else
			   redstone.setBundledOutput("back", colors.orange)
			   peripheral.wrap("right").write("active")
			   end
		  sleep(5)
	 end
end
Bomb Bloke #2
Posted 03 January 2014 - 10:40 PM
Line five reads:

redstone.setBundledOutput("back", colors.orange, false)

redstone.setBundledOutput() indeed expects a string (the side) followed by a number (the colour). You're passing it a string, number then boolean, hence it complains.

If you want to stop outputting a certain colour, you must subtract it from the combined colour signal value:

redstone.setBundledOutput("back", colours.subtract(redstone.getBundledOutput("back"), colours.orange))

Or, if you just want to stop outputting ALL colours, it's easier to just signal 0:

redstone.setBundledOutput("back", 0)

Note also that you should be pulling that event directly AFTER starting your "while" loop, not before.
LBPHacker #3
Posted 04 January 2014 - 03:31 AM
So many peripheral.wrap calls that wrap the same peripheral… I know, the garbage collector gets rid of the tables they return, but still. It somehow looks inefficient for me.
Bomb Bloke #4
Posted 04 January 2014 - 04:40 AM
Missed those - you're right, switching to something like peripheral.call() would be an improvement:

peripheral.call("right","write","active")
sgtotaku #5
Posted 04 January 2014 - 08:18 PM
Line five reads:

redstone.setBundledOutput("back", colors.orange, false)

redstone.setBundledOutput() indeed expects a string (the side) followed by a number (the colour). You're passing it a string, number then boolean, hence it complains.

If you want to stop outputting a certain colour, you must subtract it from the combined colour signal value:

redstone.setBundledOutput("back", colours.subtract(redstone.getBundledOutput("back"), colours.orange))

Or, if you just want to stop outputting ALL colours, it's easier to just signal 0:

redstone.setBundledOutput("back", 0)

Note also that you should be pulling that event directly AFTER starting your "while" loop, not before.
Thanks! i didnt know running bundled cables changed how it worked so much. this will really help me get this program working!
And thanks for the advice on improving the peripheral calls. :)/>