Jump to content




trying to create a t-flip-flop program


  • You cannot reply to this topic
4 replies to this topic

#1 sgtotaku

  • New Members
  • 2 posts

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


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

#3 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

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.

#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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")


#5 sgtotaku

  • New Members
  • 2 posts

Posted 04 January 2014 - 08:18 PM

View PostBomb Bloke, on 03 January 2014 - 10:40 PM, said:

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. :)





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users