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

Bundled Cable and multiple passwords help

Started by ace223, 29 August 2012 - 03:44 AM
ace223 #1
Posted 29 August 2012 - 05:44 AM
Hey peoples i would really love some help.

I am running the mod pack tekkit.

I am designing a factory with 4 different doors i wanted opened by computercraft.
I don't want to have 4 different computers, i just want one.

I looked into this before and found out that you can make the computer output to different coloured insulated alloy wire (RedPower Mod)


After trying to get this working I couldnt even get it to output to ANY wire, normal redstone or bundled cable.

This is what i tried to write,

room1 = "Sugar"
room2 = "Wheat"
room3 = "Cows"
room4 = "Chickens"
lightson = "Lights on"
lightsoff = "Lights oftf"

print "RAT Entry System v0.1"
write "Please Enter Room To Open"
input = read()
if input == room1 then
redstone.setBundledOutput("back", colour.red, true)  //output to red bundled cable
write "Door To Sugar Open for 60 Seconds"
sleep (60)
redstone.setBundledOutput("back", colour.red, false)
os.shutdown()
elseif input == room2 then
redstone.setBundledOutput("back", colour.yellow, true)  //output to yellow bundled cable
write "Door To Wheat Open for 60 Seconds"
sleep (60)
redstone.setBundledOutput("back", colour.yellow, false)
os.shutdown()
elseif input == room3 then
redstone.setBundledOutput("back", colour.white, true)  //output to white bundled cable
write "Door To Cows Open for 60 Seconds"
sleep (60)
redstone.setBundledOutput("back", colour.white, false)
os.shutdown()
elseif input == room4 then
redstone.setBundledOutput("back", colour.blue, true)  //output to blue bundled cable
write "Door To Chickens Open for 60 Seconds"
sleep (60)
redstone.setBundledOutput("back", colour.blue, false)
os.shutdown()
elseif input == lights then
redstone.setBundledOutput("back", colour.pink, true) //output to pink bundled cable
write "Door To Wheat Open for 60 Seconds"
sleep (60)
redstone.setBundledOutput("back", colour.pink, false)
os.shutdown()
else
write "Unknown Command Try Again"
input = read()
os.reboot
term.clear()
term.setCursorPos(1,1)
end

I added some comments, not sure how they work in computer craft, so i did C# comments (the double //)

If someone can explain to me what i am doing wrong, that would be lovely. that or just emend the code for me.
I am sort of new to ComputerCraft, i tried some code in the past and got it working, but now cant.


Thanks in advance
ace223.
Luanub #2
Posted 29 August 2012 - 06:26 AM
Couple things. The apis is colors or colours so you need to do colours.pink etc.. the setBundledOutput() function also does not require a bool to toggle the state.

Some Bundled Cable code examples:

rs.setBundledOutput("back", colours.red) -- will turn on red

rs.setBundledOutput("back", colours.blue) -- will turn on blue and turn off red since blue is the only colour listed.

Slightly more advanced for better use of multiple colours:

local c = 0 -- declare the var c as 0 or all colors off

c = colors.combine(c, colours.red) -- add red to the colours
rs.setBundledOutput("back", c ) -- turn on red

c = colors.combine(c, colours.black) -- add black to the colours
rs.setBundledOutput("back", c ) -- turn on black leaving red on

c = colors.subtract(c, colours.red) -- remove red
rs.setBundledOutput("back", c ) -- leave black on turning red off

Hopefully you're getting it, type help redpower in the terminal for more information.


Also you can remove the os.reboots and os.shutdowns and replace them with a loop of some type.


while true do
print("enter something")
local input = read()
if input == 1 then
   -do stuff
elseif input == 2 then
--do other stuff
else
--invalid entry repeat code
sleep(1)
end
end
Kazimir #3
Posted 29 August 2012 - 06:30 AM

tColor={[1]=0,[2]=1,[3]=2,[4]=4,[5]=8}	 --color.0, color.white, color.orange, color.magenta, color.lightBlue
tDoor={[1]="Door1",[2]="Door2",[3]="Door3",[4]="Door4"}
tim=10
------------------------------------------------------
function open(numb)
  rs.setBundledOutput("back", numb)
  sleep(tim)
  rs.setBundledOutput("back", tColor[1])
end
------------------------------------------------------
term.clear()
term.setCursorPos(1,1)
------------------------------------------------------
write("Please enter room to open: ")
door=read()
  if door==tDoor[1] then open(tColor[2])
   elseif door==tDoor[2] then open(tColor[3])
   elseif door==tDoor[3] then open(tColor[4])
   elseif door==tDoor[4] then open(tColor[5])
  end
------------------------------------------------------
term.clear()
term.setCursorPos(1,1)

[/EDITED]
Luanub #4
Posted 29 August 2012 - 07:35 AM

tDoor={[1]="Door1",[2]="Door2",[3]="Door3",[4]="Door4"}	--names doors
tim=10											   --time
function open(numb)
  rs.setBundledOutput("back", numb)
  write(tDoor[numb].." open for "..tim.." seconds")
  sleep(tim)
  rs.setBundledOutput("back", 0)
end

term.clear()
term.setCursorPos(1,1)
write("Please enter room to open: ")
door=read()
  if door==tDoor[1] then open(1)
	elseif door==tDoor[2] then open(2)
	elseif door==tDoor[3] then open(3)
	elseif door==tDoor[4] then open(4)
  end
term.clear()
term.setCursorPos(1,1)

This is missing a huge portion… How does it know which colors to use for the rs commands? You're passing a number to the open function so it is going to do something like

rs.setBundledOutput("back", 1)
Which is not going to function as desired.. For one there is no color for the decimal number 3…

If your going to give a solution when one has already been provided please make sure it works so you don't frustrate/confuse the person asking for help even more..


EDIT: Here is what the corrected code should look like:
Spoiler

room1 = "Sugar"
room2 = "Wheat"
room3 = "Cows"
room4 = "Chickens"
lightson = "Lights on"
lightsoff = "Lights oftf"

while true do
term.clear()
term.setCursorPos(1,1)
print "RAT Entry System v0.1"
write "Please Enter Room To Open"
input = read()
if input == room1 then
  redstone.setBundledOutput("back", colours.red)  //output to red bundled cable
  write "Door To Sugar Open for 60 Seconds"
  sleep (60)
  redstone.setBundledOutput("back", 0)
elseif input == room2 then
  redstone.setBundledOutput("back", colours.yellow)  //output to yellow bundled cable
  write "Door To Wheat Open for 60 Seconds"
  sleep (60)
  redstone.setBundledOutput("back", 0)
elseif input == room3 then
  redstone.setBundledOutput("back", colours.white)  //output to white bundled cable
  write "Door To Cows Open for 60 Seconds"
  sleep (60)
  redstone.setBundledOutput("back", 0)
elseif input == room4 then
  redstone.setBundledOutput("back", colours.blue)  //output to blue bundled cable
  write "Door To Chickens Open for 60 Seconds"
  sleep (60)
  redstone.setBundledOutput("back", 0)
elseif input == lights then -- this line looks like it may have an issue. I dont see a var called lights
  redstone.setBundledOutput("back", colours.pink) //output to pink bundled cable
  write "Door To Wheat Open for 60 Seconds"
  sleep (60)
  redstone.setBundledOutput("back", 0)
else
  write "Unknown Command Try Again"
end
end
Edited on 29 August 2012 - 05:48 AM
Kazimir #5
Posted 29 August 2012 - 07:45 AM
Oops))
Yes, you're right, I accidentally deleted the part program and made ​​a wrong start, now edited.
ace223 #6
Posted 30 August 2012 - 03:05 AM
Thanks, i will hopefully get a chance to try it tonight.
and the lighting i will add later.

i will let you all know if it works :)/>/>