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

bundleCable and computercraft

Started by rocknrolly, 17 January 2013 - 10:08 PM
rocknrolly #1
Posted 17 January 2013 - 11:08 PM
hello!

i need help with Bundle Cables to turn on and off with computer

so , i have a nuclear reactor wich working perfect , with a computer but i want to make this think


i have 3 lamps , 1 red , 1 yellow , 1 green

i use bundle cables , to connect all the 3 lam , 2 door ,1 cooling system , and the nuclear reactor ! Its working fine , but i have one little problem with these cables


when the reactor is on idle , i want the red lamp turn on ( oke its workin)
when the reactor working , the green lamp turn on (its working 2)
when the door is opend , the yellow light up 2 , but if still i have exemple the red lamp on , dont turn the red off , and turn on the yellow , turn on all 2 ! , but if the green lamp was lightnen up , turn on the yellow and green,!

sorry for my language . i speak a little bad the english..


i think somthing like this :


if

c = colors.combine ( c, colors.red )
rs.setBundledOutput("back", c ) == true – turns on the red

then

c = colors.combine ( c, colors.yellow )
rs.setBundledOutput("back", c ) – turns on yellow leaving red on

end
Luanub #2
Posted 17 January 2013 - 11:16 PM
You've pretty much got it

c = 0 -- all colors off

c = colors.combine(c, colors.red)
rs.setBundledOutput("back", c ) -- red is on

c = colors.combine(c, colors.yellow)
rs.setBundledOutput("back", c ) -- red and yellow

c = colors.subtract(c, colors.red)
rs.setBundledOutput("back", c ) -- just yellow

You don't really need an if statement unless you want to check a color then you would want to do something like

if rs.testBundledInput("back", colors.red) then --to test an input
  -- do something
end

if rs.testBundledOutput("back", colors.red) then --to test an Output
  -- do something
end
theoriginalbit #3
Posted 17 January 2013 - 11:20 PM
You've pretty much got it

c = 0 -- all colors off

c = colors.combine(c, colors.red)
rs.setBundledOutput("back", c ) -- red is on

c = colors.combine(c, colors.yellow)
rs.setBundledOutput("back", c ) -- red and yellow

c = colors.subtract(c, colors.red)
rs.setBundledOutput("back", c ) -- just yellow
That will ignore the state of them on chunk reload…
i would suggest instead of

c = 0
this instead

c = rs.getBundledInput( "back" )
that way your combining or subtracting from the actual cables, not the assumed 'off'…
Edited on 17 January 2013 - 10:22 PM
rocknrolly #4
Posted 17 January 2013 - 11:30 PM
in my startup file , is a script wich turn on the red lamp automatic , when the computer is start up , ( cuse i have many options on menu , (turn off (red lamp), turn on ( green lamp) , open door( yellow lamp on). close door(yellow lamp off) , but now still i have this kinde


c = rs.getBundledInput( "back" )

c = colors.combine(c, colors.red)
rs.setBundledOutput("back", c ) – red is on

c = colors.combine(c, colors.yellow)
rs.setBundledOutput("back", c ) – red and yellow

c = colors.combine(c, colors.green)
rs.setBundledOutput("back", c ) – Green lamp
c = colors.combine(c, colors.blue)
rs.setBundledOutput("back", c ) – Open the door
, so when i turn on the pc , the red light on , and i wanna to open the door , and i need to light up the red and yellow lamp , but if i start first the reactor , the red turn off, the green turn on ,and after i wanna to open the door , and turn on the green with yellow , and mixed , if u know what i mean…
rocknrolly #5
Posted 17 January 2013 - 11:31 PM
that is why i want to resolve my problem , with "IF" , and ELSEIF , and THEN , but it dosnt work :(/> i dont know why
theoriginalbit #6
Posted 17 January 2013 - 11:33 PM
can you post all your code? use pastebin if its easier :)/>
rocknrolly #7
Posted 17 January 2013 - 11:38 PM
startup

local side = "bottom"
local password = "sajt"
local opentime = 5
rs.setBundledOutput("back", colours.red)

term.clear()
term.setCursorPos(1,1)
print("some text")
write("Jelszo kotelezo:")
local input = read("*")
if input == (password) then
term.clear()
term.setCursorPos(1,1)
shell.run("menu")
else
term.clear()
term.setCursorPos(1,1)
print("Password incorrect")
sleep(2)
term.clear()
shell.run("startup")
end


menu


local w,h = term.getSize()
function printCentred( y, s )
	local x = math.floor((w - string.len(s)) / 2)
	term.setCursorPos(x,y)
	term.clearLine()
	term.write( s )
end
local nOption = 1
-- Display menu
local function drawMenu()
	term.clear()
	term.setCursorPos(1,1)
	term.write( "some text" )
	print("")
	term.setCursorPos(w-11,1)
	if nOption == 1 then
	term.write( "1" )
	elseif nOption == 2 then
	term.write( "2" )
	elseif nOption == 3 then
	term.write ("3")
	elseif nOption == 4 then
	term.write ("4")
	else
	term.write( "5" )
	end
sleep(0)  
end
-- Display the frontend
term.clear()
local function drawFrontend()
	printCentred( math.floor(h/2) - 5, "" )
	printCentred( math.floor(h/2) - 4, "" )
	printCentred( math.floor(h/2) - 3, "" )
	printCentred( math.floor(h/2) - 2, "Valassz egy opciot" )
	printCentred( math.floor(h/2) - 1, "" )
	printCentred( math.floor(h/2) + 0, ((nOption == 1) and "[ Turn On]") or "Turn On" )
	printCentred( math.floor(h/2) + 1, ((nOption == 2) and "[ Turn Off]") or "Turn Off" )
  
   printCentred( math.floor(h/2) + 2, ((nOption == 3) and "[ Open Door]") or "Open Door")
   printCentred( math.floor(h/2) + 3, ((nOption == 4) and "[ Close Door]") or "Close Door")
	printCentred( math.floor(h/2) + 4, ((nOption == 5) and "[ LogOut ]") or "LogOut" )
	printCentred( math.floor(h/2) + 5, "" )
end

-- Call functions for display menu
drawMenu()
drawFrontend()
while true do
	local e,p = os.pullEvent()
	if e == "key" then
		local key = p
		if key == 17 or key == 200 then
			-- Up
			if nOption > 1 then
				nOption = nOption - 1
				drawMenu()
				drawFrontend()
			end
		elseif key == 31 or key == 208 then
			-- Down
			if nOption < 5 then -- Change 3 by the number of option.
				nOption = nOption + 1
				drawMenu()
				drawFrontend()
			end
		elseif key == 28 then
			-- Enter
			break
		end
	end
end
term.clear()
-- Conditions
if nOption == 1 then
	term.setCursorPos(1,1)
	print("Reaktor melegitese...")
sleep(3)
shell.run("r-on")
print("Reactor mukodesben.")
shell.run("menu")
elseif nOption == 2 then
	term.setCursorPos(1,1)
print("Reaktor hutese...")
sleep(2)
print("Reactor kikapcsolva")
shell.run("r-off")
elseif nOption == 3 then
	term.setCursorPos(1,1)
		print("Az ajtok nyitodnak,vigyazat!")
		sleep(2)
		shell.run("don")
		sleep(1)
		shell.run("menu")
elseif nOption == 4 then
	term.setCursorPos(1,1)
		print("Azt ajtok zarodnak!")
		sleep(1)
		shell.run("doff")
shell.run("menu")
else
term.setCursorPos(1,1)
print("Logging out...")
sleep(2)
shell.run("startup")
end


r-on


rs.setBundledOutput("back", colors.green)

r-off


rs.setBundledOutput("back", 0)

rs.setBundledOutput("back", colours.green)
rocknrolly #8
Posted 17 January 2013 - 11:41 PM
this part is working fine , but now i need a second code , wich one , turn on the yellow lamp , when i pen the door with one another program !

with the program "Don" and turn off with the program "DOFF"

DON


c = rs.getBundledInput( "back" )
c = colors.combine(c, colors.red)
rs.setBundledOutput("back", c ) -- red is on
c = colors.combine(c, colors.yellow)
rs.setBundledOutput("back", c ) -- red and yellow
c = colors.combine(c, colors.green)
rs.setBundledOutput("back", c ) -- just yellow
c = colors.combine(c, colors.blue)
rs.setBundledOutput("back", c ) -- just yellow


DoFF



remcol(colors.blue, "back")