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

rednet cables. choose color!

Started by zedlander1000, 03 February 2014 - 03:39 PM
zedlander1000 #1
Posted 03 February 2014 - 04:39 PM
Hello, i dont really have a program yet but im going to develop one.

The program i want to create is with rednet and the color cables. So basically, im making a program for my smeltry to make it automated and i want to use rednet cables to auto click my faucets that pour the molten stuff in the basins. Im going to have many colors hooked up to certain faucets. How do i output a signal to the color wite, and the other colors? in this program, i also want to choose what i want to activate and stop. Can some one help me with it?

i mostly need help with how to use the rednet cables and deciding color.
Bomb Bloke #2
Posted 03 February 2014 - 06:15 PM
Take a read through these two APIs first. In particular, you're interested in the redstone API's four "bundled" functions.

Say you want to output the colour white out your right side. You'd do this:

rs.setBundledOutput("right",colours.white)

Say you've got another computer receiving that signal on its left, and you want to check whether or not white is active. You'd do this:

if rs.testBundledInput("left",colours.white) then ...

Say you want the first computer to enable the colour orange, without disrupting the colour it's already sending. You'd do this:

rs.setBundledOutput("right",colours.combine(rs.getBundledOutput("right"),colours.orange))

And so forth.
zedlander1000 #3
Posted 03 February 2014 - 07:14 PM
how do i make it decide by one cable?
surferpup #4
Posted 04 February 2014 - 01:44 AM
I think what you are asking is this (correct me if I am wrong):

You have a computer with one bundled cable going all over the place.
You want to be able to send signal to various devices attached to this bundled cable.

Solution:

All you have to do is use rs.setBundledOutput(side,color), where side is a string representation of the side the cable is attached to the computer and color is a numeric value representing all of the colors that are currently turned on.

For each device you attach the cable to, you will need to use a wrench to set the color going to that device. There are 16 colors in a bundled cable. So lets say you have a redstone lamp and a rubber chicken hooked up to the cable. When you turn on the lamp, you do not necessarily want to fry the chicken. Likewise, when you deem to electrocute the rubber chicken, you want to either have the lamp on or off. You have connected the bundled cable to the back of the computer.

So, using a wrench, set the lamp to colors.blue, and the rubber chicken connection to colors.red.


-- turn off all colors
rs.setBundledOutput("back",0)

-- electrocute the chicken, but keep the lamp off.
rs.setBundledOutput("back", colors.red)

-- now also turn on the lamp
rs.setBundledOutput("back",colors.combine(rs.getBundledOutput("back"),colors.blue))

-- now turn off the chicken

rs.setBundledOutput("back",colors.subtract(rs.getBundledOutput("back"),colors.red))

-- test to see if the chicken still is getting the juice

print( tostring(colors.test(rs.getBundledOutput("back"),colors.red)))-- true if on, false if off


Hope that helps.
zedlander1000 #5
Posted 04 February 2014 - 05:41 PM
its not a bundle cable
Lyqyd #6
Posted 04 February 2014 - 07:36 PM
What? Please post a screenshot of what you've built in-game. I'm not quite sure what you're asking at this point.
Bomb Bloke #7
Posted 04 February 2014 - 07:49 PM
Bear in mind that MineFactory Reloaded's "rednet" cables are, for the purposes of the redstone API, "bundled".
zedlander1000 #8
Posted 04 February 2014 - 08:26 PM


this is what im trying to build.

the faucets will be auto clicked by the computer using redstone. I want it to hold the signal i think so it will pour into the basin.

nope, nvm i just need a redstone pulse that repeats its self so it makes more than one thing.

one pulse = one object
after that one object is done,
another pulse is needed to make another thing.

i want to decide between white and orange via computer and stop it via computer
zedlander1000 #9
Posted 04 February 2014 - 08:40 PM
ok, ive developed some code. not totally done. i cant get it to output a redstone signal.

i have 2 programs:

program: startup




while true do
term.clear()
term.setCursorPos(1,1)

print("Choose your output:")
print("-1 signal white")
print("-2 signal orane")
input = read()
shell.run(input)
end

program: 1 (aka the program that should choose the color white)





print("You sure you want to choose the output 'white'?")
print("yes/no")
choose = read()

if choose == "yes" then
redstone.setBundledOutput("left",1)
end
Bomb Bloke #10
Posted 04 February 2014 - 09:28 PM
An oddity of the redstone/peripheral APIs is that right/left are reversed. In the setup you've built, sending an output through the "left" side results in it coming out the side of the computer you view as being on the left… as opposed to having it come out the computer's left side.

To confuse matters further, turtles with modems (which are strapped onto their right side) must refer to those modems as being on their right side. As opposed to computers, where plonking a modem on their right side means you must tell them they're on the left.

Go figure.
theoriginalbit #11
Posted 04 February 2014 - 09:36 PM
-snip-
I've figured it out to be to do with the way you look at them… meaning the sides are always relative to how you're looking at it. a computer you use from the front meaning the computers left is your right, whereas normally when using a Turtle it is facing away from you making its right also your right.
zedlander1000 #12
Posted 04 February 2014 - 10:02 PM
i couldnt get it to work from the left or right :(/> but i got it working on the top :)/> it works now. all i need to do now is add the auto mation.

im having a prblem though




print("You sure you want to choose the output 'white'?")
print("yes/no")
print(" ")
choose = read()

if choose == "yes" then
redstone.setBundledOutput("top",1)
elseif choose == "no" then

print("exiting to signal decision menu....")
io.sleep(3.0)
print("Loading menu:")
print(".")
io.sleep(3.0)
term.clearLine()
print("..")
io.sleep(3.0)
term.clearLine()
print("...")
io.sleep(3.0)
print("Loading successful")
io.sleep(2.0)
exit()
end



elseif choose == "no" then

print("exiting to signal decision menu....")
io.sleep(3.0)
print("Loading menu:")
print(".")
io.sleep(3.0)
term.clearLine()
print("..")
io.sleep(3.0)
term.clearLine()
print("...")
io.sleep(3.0)
print("Loading successful")
io.sleep(2.0)
exit()
end
if i say no, it outputs no text to the console.
Edited on 04 February 2014 - 09:02 PM
surferpup #13
Posted 04 February 2014 - 11:35 PM
Troubleshoot this by printing out what choose is right after you read it. Make sure it actually does say "no."

As for your cable, hook the white up to a redstone lamp. If it turns on, there is signal
zedlander1000 #14
Posted 05 February 2014 - 07:54 AM
ye, it doesnt print it to the console nor does it repeate
Bomb Bloke #15
Posted 05 February 2014 - 08:14 AM
What DOES it do?
surferpup #16
Posted 05 February 2014 - 08:25 AM
Just a little on norms: I usually don't see io.sleep statements. They are usually written os.sleep or sleep. Try this:



print("You sure you want to choose the output 'white'?")
print("yes/no")
print(" ")
choose = read()

if choose == "yes" then
  redstone.setBundledOutput("top",1)
elseif choose == "no" then
  print("exiting to signal decision menu....")
  sleep(3.0)
  print("Loading menu:")
  print(".")
  sleep(3.0)
  term.clearLine()
  print("..")
  sleep(3.0)
  term.clearLine()
  print("...")
  sleep(3.0)
  print("Loading successful")
  sleep(2.0)
  exit() -- unecessary
end

Also – don't think the exit() is necessary. If you want to shut down, just use os.shutdown()

I tested this code – other than the exit(), it works as desired.
Edited on 05 February 2014 - 07:33 AM
surferpup #17
Posted 05 February 2014 - 08:49 AM
I tested both my version as well as your original version. Please use the version I wrote. It works. Yours has issues (the io.sleep does not work as you expect)
zedlander1000 #18
Posted 05 February 2014 - 11:02 AM
What DOES it do?
so far, i run it, it only prints the yes no stuff and then fills the basin once. i want it to repeate. ps i havent used surferpu's code yet, do once i try that, il lreport back. after i get the no part working, i just need the yes part to repeat its self and then stop when i say for it to stop.

help with that please?

edit: ok your version works except term.clearLine() doesnt work
edit 2: term.clear() it doesnt print to the top of the screen. it prints basically where it would print below the text above it but with out the text above it.
Edited on 05 February 2014 - 10:14 AM
zedlander1000 #19
Posted 05 February 2014 - 11:17 AM
ok, i got the clear screen to work. had to add term.setCursorPos(1,1)

but term.clearLine still doesnt work :/.

do i need a number like term.clearLine(#of line)?
surferpup #20
Posted 05 February 2014 - 02:08 PM
It's working fine, just on the next line. print() prints on the current line and then advances the terminal to the next line. Use write instead. Just reset your cursor position and rewrite what you want there.
zedlander1000 #21
Posted 05 February 2014 - 02:38 PM



print("You sure you want to choose the output 'white'?")
print("yes/no")
print(" ")
choose = read()
term.clear()
term.setCursorPos(1,1)


if choose == "yes" then
while true do
redstone.setBundledOutput("top",1)
sleep(13.0)
redstone.setOutput("top",false)
print("Item made")
end
elseif choose == "no" then

print("exiting to signal decision menu....")
sleep(3.0)
print("Loading menu:")
print(".")
sleep(3.0)
term.clearLine(3)
term.setCursorPos(1,3)
print("..")
sleep(3.0)
term.clearLine(3)
term.setCursorPos(1,3)
print("...")
sleep(3.0)
print("Loading successful")
sleep(2.0)

end

every thing is working but this.


if choose == "yes" then
while true do
redstone.setBundledOutput("top",1)
sleep(13.0)
redstone.setOutput("top",false)
print("Item made")
end
how do i keep on making it put out a signal every 13 seconds? and how do i make it stop when i want it to stop?
surferpup #22
Posted 05 February 2014 - 02:47 PM
look at your loop – you set output to 1, pause 3, set it to false (should be 0) then do it again. Problem is that there is no pause between when you turn it off and when it is turned on:

Try this:


if choose == "yes" then
  while true do
    redstone.setBundledOutput("top",1)
    sleep(13.0)
    redstone.setOutput("top",0)
    sleep(1)
    print("Item made")
  end

... elseif etc
zedlander1000 #23
Posted 05 February 2014 - 03:29 PM
it still doesnt repeat its self
surferpup #24
Posted 05 February 2014 - 03:43 PM
Please post your code as it currently is.
zedlander1000 #25
Posted 05 February 2014 - 04:11 PM



print("You sure you want to choose the output 'white'?")
print("yes/no")
print(" ")
choose = read()
term.clear()
term.setCursorPos(1,1)


if choose == "yes" then
while true do
redstone.setBundledOutput("top",1)
sleep(13.0)
redstone.setBundledOutput("top",0) --redstone.setOutput("top",0) doesnt work either
sleep(1)
print("Item made")
end
elseif choose == "no" then

print("exiting to signal decision menu....")
sleep(3.0)
print("Loading menu:")
print(".")
sleep(3.0)
term.clearLine(3)
term.setCursorPos(1,3)
print("..")
sleep(3.0)
term.clearLine(3)
term.setCursorPos(1,3)
print("...")
sleep(3.0)
print("Loading successful")
sleep(2.0)

end
Edited on 05 February 2014 - 03:11 PM
surferpup #26
Posted 05 February 2014 - 04:20 PM
Try this and tell me what happens:


print("You sure you want to choose the output 'white'?")
print("yes/no")
print(" ")
choose = read()
term.clear()
term.setCursorPos(1,1)


if choose == "yes" then
  while true do
	redstone.setBundledOutput("top",1)
	print ("ON")  -- test line
	sleep(13.0)
	redstone.setBundledOutput("top",0)
	print ("OFF")  -- test line
	sleep(1)
	print("Item made")
  end
elseif choose == "no" then
  print("exiting to signal decision menu....")
  sleep(3.0)
  print("Loading menu:")
  print(".")
  sleep(3.0)
  term.clearLine(3)
  term.setCursorPos(1,3)
  print("..")
  sleep(3.0)
  term.clearLine(3)
  term.setCursorPos(1,3)
  print("...")
  sleep(3.0)
  print("Loading successful")
  sleep(2.0)
end

If you see the ON / OFF printout, then the code works. At that point we will need to look at your actual Minecraft implementation (like are your devices really connected to rednet cable or do you just think they are).
Edited on 05 February 2014 - 03:20 PM
zedlander1000 #27
Posted 05 February 2014 - 04:25 PM
it works but it doesnt make another object the second time through.

:D/> nvm, it works

now, while its in the middle of running the while true do loop, how do i make it so that any time i can choose it to exit the loop?
surferpup #28
Posted 05 February 2014 - 04:51 PM
How do you want to exit the loop? Key press, redstone event? monitor touch event? What?
zedlander1000 #29
Posted 05 February 2014 - 05:10 PM
key press
Edited on 05 February 2014 - 04:10 PM
surferpup #30
Posted 05 February 2014 - 11:02 PM
To do this, you are going to need to use the parallel.api. However, you may not be ready for that technique. Your simplest way might be to have a lever. that, when on, will allow the while loop to go. When off, it stops the while loop. You can modify the while loop to be while redstone.testBundledInput(side, color) do where the color is the color of the rednet cable connected to the lever.

To do the key press thing, you will need to turn the while loop into a function and have a separate function wait for a key event. Here is your code, re-written (and cleaned up a bit, setting local variables and functions where appropriate) which accomplishes what you asked for:



local function makeThings()
  while true do
	redstone.setBundledOutput("top",1)
	--print ("ON")  -- test line
	sleep(13)
	redstone.setBundledOutput("top",0)
	--print ("OFF")  -- test line
	sleep(1)
	print("Item made")
  end
end

local function waitForKey()
  while ({os.pullEvent("key")})[2] ~= keys.q do
  end
end

print("You sure you want to choose the output 'white'?")
print("yes/no")
print(" ")
local choose = read()
term.clear()
term.setCursorPos(1,1)

if choose == "yes" then
  parallel.waitForAny(makeThings,waitForKey)
elseif choose == "no" then
  print("exiting to signal decision menu....")
  sleep(3.0)
  print("Loading menu:")
  print(".")
  sleep(3.0)
  term.clearLine(3)
  term.setCursorPos(1,3)
  print("..")
  sleep(3.0)
  term.clearLine(3)
  term.setCursorPos(1,3)
  print("...")
  sleep(3.0)
  print("Loading successful")
  sleep(2.0)
end



That will work the way you described. To quit, press the "q" key.

Mind you, there are more efficient ways to go about what you want to do, but this will work the way you want. I commented out the test print lines.

If you want to wait for any key, change the function waitForKey to this:


local function waitForKey()
  while true do
	os.pullEvent("key")
  end
end

Please make sure to up vote the responses to your question that helped you. Several people contributed to helping you on your project. They like the feedback :)/>
Edited on 05 February 2014 - 10:06 PM
zedlander1000 #31
Posted 06 February 2014 - 03:58 PM
thanks :)/> thanks alot! thanks all for your help. ps if i want to change the key, do i do key.<what key i want>?
zedlander1000 #32
Posted 06 February 2014 - 05:08 PM
To do this, you are going to need to use the parallel.api. However, you may not be ready for that technique. Your simplest way might be to have a lever. that, when on, will allow the while loop to go. When off, it stops the while loop. You can modify the while loop to be while redstone.testBundledInput(side, color) do where the color is the color of the rednet cable connected to the lever.

To do the key press thing, you will need to turn the while loop into a function and have a separate function wait for a key event. Here is your code, re-written (and cleaned up a bit, setting local variables and functions where appropriate) which accomplishes what you asked for:



local function makeThings()
  while true do
	redstone.setBundledOutput("top",1)
	--print ("ON")  -- test line
	sleep(13)
	redstone.setBundledOutput("top",0)
	--print ("OFF")  -- test line
	sleep(1)
	print("Item made")
  end
end

local function waitForKey()
  while ({os.pullEvent("key")})[2] ~= keys.q do
  end
end

print("You sure you want to choose the output 'white'?")
print("yes/no")
print(" ")
local choose = read()
term.clear()
term.setCursorPos(1,1)

if choose == "yes" then
  parallel.waitForAny(makeThings,waitForKey)
elseif choose == "no" then
  print("exiting to signal decision menu....")
  sleep(3.0)
  print("Loading menu:")
  print(".")
  sleep(3.0)
  term.clearLine(3)
  term.setCursorPos(1,3)
  print("..")
  sleep(3.0)
  term.clearLine(3)
  term.setCursorPos(1,3)
  print("...")
  sleep(3.0)
  print("Loading successful")
  sleep(2.0)
end



That will work the way you described. To quit, press the "q" key.

Mind you, there are more efficient ways to go about what you want to do, but this will work the way you want. I commented out the test print lines.

If you want to wait for any key, change the function waitForKey to this:


local function waitForKey()
  while true do
	os.pullEvent("key")
  end
end

Please make sure to up vote the responses to your question that helped you. Several people contributed to helping you on your project. They like the feedback :)/>
a problem came up.

i just made program 2 (its called 2) for the color orange but its not working.




local function makeThings()
  while true do
    redstone.setBundledOutput("top",2)
    print("On")
    sleep(13)
    redstone.setBundledOutput("top",0)
    print("Off")
    sleep(1)
    print("Item made")
  end
end

local function waitForKey()
  while ({os.pullEvent("key")})[2] ~= keys.q do
  end
end

print("You sure you want to choose the output 'orange'?")
print("yes/no")
print(" ")
local choose = read()
term.clear()
term.setCursorPos(1,1)

if choose == "yes" then
  parallel.waitForAny(makeThings,waitForKey)
elseif choose == "no" then
  print("exiting to signal decision menu....")
  sleep(2)
  print("Loading menu:")
  print(".")
  sleep(3)
  term.clearLine(3)
  term.setCursorPos(1,3)
  print("..")
  sleep(3)
  term.clearLine(3)
  term.setCursorPos(1,3)
  print("...")
  sleep(3)
  print("Loading successful")
  sleep(2)
end

wow lol xD my smeltry was out of stuff to make objects. NVM
surferpup #33
Posted 06 February 2014 - 05:26 PM
thanks :)/> thanks alot! thanks all for your help. ps if i want to change the key, do i do key.<what key i want>?

You are welcome.


For "g", you would do

keys.g

Look up the keys table for ComputerCraft.

Do you have your problem resolved now??