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

throw 3 switches and continue

Started by Xixili, 29 August 2015 - 11:43 PM
Xixili #1
Posted 30 August 2015 - 01:43 AM
Its hard to find the right topic title but I will explain it here in more detail.

I have 3 switches connected on bundled cables.

brown, green and red.

I want that the computer wait forthe levers before it continues.

The 3 levers needs to be switched before the computer continues.

But my problem is that the computer already continues at 1 lever.

this is the code:

os.pullEvent("redstone")
if rs.testBundledInput("left", colours.brown) then
term.setTextColor(colors.red)
term.setCursorPos(38, 5)
term.write("unlocked")
end
 
os.pullEvent("redstone")
if rs.testBundledInput("left", colours.green) then
term.setTextColor(colors.red)
term.setCursorPos(38, 6)
term.write("unlocked")
end
os.pullEvent("redstone")
if rs.testBundledInput("left", colours.red) then
term.setTextColor(colors.red)
term.setCursorPos(38, 7)
term.write("unlocked")
end
sleep(3)
rs.setBundledOutput("left", colours.black+colours.pink+colours.white)
sleep(5)


And the whole code can be found here:
http://pastebin.com/6MwycAaE
Bomb Bloke #2
Posted 30 August 2015 - 03:28 AM
When you want your script to process a bit of code until a certain condition occurs, you use a "while" or a "repeat" loop:

term.setTextColor(colors.red)

while not rs.testBundledInput("left", colours.combine(colours.brown, colours.green, colours.red)) do
	term.setCursorPos(38, 5)
	term.write(rs.testBundledInput("left", colours.brown) and "unlocked" or "locked  ")

	term.setCursorPos(38, 6)
	term.write(rs.testBundledInput("left", colours.green) and "unlocked" or "locked  ")

	term.setCursorPos(38, 7)
	term.write(rs.testBundledInput("left", colours.red) and "unlocked" or "locked  ")

	os.pullEvent("redstone")
end