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

Need help with Bundled cable and user input

Started by Z0NAT3D, 26 December 2012 - 07:03 AM
Z0NAT3D #1
Posted 26 December 2012 - 08:03 AM
Hey. So I am making a program with bundled cables for RP2 and some lights. I have typed a program and ran it in the latest version of ComputerCraft for 1.4.6 and it doesn't work. I think that I am having some problems with user Input. I the program, I type "programs" and it appears with the words "Would you like the lights on or off", so I then type "on" and it skips through both "if, then" statements and procedes to clear the screen and reset the cursor position like it should. I do have all the cables coming correctly out the back of the computer and the white cable coming out of the bundled followed by the red alloy wire. I am using the black wire as a sort of "ground" wire if you are familiar with electricity. Any help would be great! Thanks.



term.clear()
term.setCursorPos(1,1)

print("Would you like the lights on or off")

yes = "yes"
no = "no"

local input = read()



if input == yes then
print("Lights are on")
redstone.setBundledOutput("back", colors.white)
end

if input == no then
print("Lights are off")
redstone.setBundledOutput("back", colors.black)
end

term.clear()
term.setCursorPos(1,1)
Cozzimoto #2
Posted 26 December 2012 - 08:39 AM
instead of creating variables to compare you can compare the input already with the ==.
and string.lower makes your input lower case so upper case doesnt matter and you can add in more than one type of compares to add more flexability in your program

my changes include:
Spoilerlocal input = read() to local input = io.read()

input = string.lower(input)

removed yes = "yes"
removed no = "no"

if input == yes then to if input == "yes" or input == "y" then
if input == no then to if input == "no" or input == "n" then


term.clear()
term.setCursorPos(1,1)

print("Would you like the lights on or off")

local input = io.read()

input = string.lower(input)

if input == "yes" or input == "y" then
  print("Lights are on")
  rs.setBundledOutput("back", colors.white)

elseif input == "no" or input == "n" then
  print("Lights are off")
  rs.setBundledOutput("back", colors.black)
end

term.clear()
term.setCursorPos(1,1)
KaoS #3
Posted 26 December 2012 - 07:02 PM
quick question. why are you printing a notification about whether the lights have been turned on or off and immediately clearing the screen? you won't see that message