Jump to content




Need help with Bundled cable and user input

computer lua help

2 replies to this topic

#1 Z0NAT3D

  • New Members
  • 2 posts

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)

#2 Cozzimoto

  • Members
  • 221 posts
  • LocationDallas, Tx

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:
Spoiler

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)


#3 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users