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

end while by rs input

Started by darcline, 29 January 2013 - 05:15 AM
darcline #1
Posted 29 January 2013 - 06:15 AM
hello the title is all :D/>

but i have here sme code, because i will that when redstone input comes that a while will end but it´s not working, and sorry for bad english

while true do
x = redstone.setBundledOutput("right", colors.blue)
local x = false

while x == false do
term.clear()
local w, h = term.getSize()
for i=0, w, 1 do
term.setCursorPos(1+i,1)
print("#")
end
for i=0, w, 1 do
term.setCursorPos(1+i,h)
print("#")
end
for i=0, h, 1 do
term.setCursorPos(1,1+i)
print("#")
end
for i=0, h, 1 do
term.setCursorPos(w,1+i)
print("#")
end

term.setCursorPos(2,2)
print("Waehlen sie bitte ein Option:")
term.setCursorPos(3,3)
print("<U> Fahrstuhl hochfahren")
term.setCursorPos(3,4)
print("<D> Fahrstuhl runterfahren")
term.setCursorPos(3,6)
local eingabe = read()

if (eingabe == "U" or eingabe == "u" and redstone.testBundledInput("right", colors.white+colors.orange)) == true then
for i=0,13 do
redstone.setBundledOutput("right", colors.green)
sleep(0.5)
redstone.setBundledOutput("right", 0)
sleep(0.5)
end
end


if (eingabe == "D" or eingabe == "d" and redstone.testBundledInput("right", colors.white+colors.orange)) == true then
for i=0,13 do
redstone.setBundledOutput("right", colors.brown)
sleep(0.5)
redstone.setBundledOutput("right", 0)
sleep(0.5)
end
else
os.reboot()
end
end
end

please helpt me and it must a bundled cable input with color blue
bjornir90 #2
Posted 29 January 2013 - 07:16 AM
You need to use

if redstone input then --put any condition here
 break
end
darcline #3
Posted 29 January 2013 - 08:51 AM
ahm its not working the program starts and stops.

can you write it in the full script ?
OmegaVest #4
Posted 29 January 2013 - 09:10 AM
Okay, soa question first:

Does anything other than the computer turn the blue line on? If not, the computer will ignore this line as an input for the purposes of testBundledInput.

However, once you have rectified that, you will simply need to do this:

Spoiler

while rs.testBundledInput("right", colors.blue) then
   -- code to be looped
end

Like bjornir90 said.



Also, testBundledInput I think only works with one color. To test for multiple inputs, you will either need multiple rs tests or use colors.test, which will take a set of colors as opposed to a single color. You could also use colors.combine(), but I can't test that functionality at the moment.



EDIT: Thanks Orwell.
Orwell #5
Posted 29 January 2013 - 09:17 AM
Also, testBundledInput I think only works with one color. To test for multiple inputs, you will either need multiple rs tests or use colors.test, which will take a set of colors as opposed to a single color. You could also use colors.combine(), but I can't test that functionality at the moment.
You have a typo in the spoiler and yes, testBundledInput does take the sum of color values as a parameter and reacts as expected. However, simply taking the sum of colors will only work if none of the colors are used more than once. Keep that in mind. ;)/> xor'ing them or using colors.combine() is indeed a better method.
darcline #6
Posted 29 January 2013 - 10:18 AM
i need only one color ;)/> but when i start the program he says me that he want a do at line 2
OmegaVest #7
Posted 29 January 2013 - 10:22 AM
My error. It should be a do instead of then. My fingers are often quicker than my brain.
darcline #8
Posted 29 January 2013 - 10:42 AM
i changed to do the program start and stops quickly heres the code now

local x = false
while rs.testBundledInput("right", colors.blue) do
term.clear()
local w, h = term.getSize()
for i=0, w, 1 do
term.setCursorPos(1+i,1)
print("#")
end
for i=0, w, 1 do
term.setCursorPos(1+i,h)
print("#")
end
for i=0, h, 1 do
term.setCursorPos(1,1+i)
print("#")
end
for i=0, h, 1 do
term.setCursorPos(w,1+i)
print("#")
end

term.setCursorPos(2,2)
print("Waehlen sie bitte ein Option:")
term.setCursorPos(3,3)
print("<U> Fahrstuhl hochfahren")
term.setCursorPos(3,4)
print("<D> Fahrstuhl runterfahren")
term.setCursorPos(3,6)
local eingabe = read()

if (eingabe == "U" or eingabe == "u" and redstone.testBundledInput("right", colors.white+colors.orange)) == true then
for i=0,13 do
redstone.setBundledOutput("right", colors.green)
sleep(0.5)
redstone.setBundledOutput("right", 0)
sleep(0.5)
end
end


if (eingabe == "D" or eingabe == "d" and redstone.testBundledInput("right", colors.white+colors.orange)) == true then
for i=0,13 do
redstone.setBundledOutput("right", colors.brown)
sleep(0.5)
redstone.setBundledOutput("right", 0)
sleep(0.5)
end
else
os.reboot()
end
break
end