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

A Matter of Values

Started by Nikolai, 02 December 2012 - 07:38 PM
Nikolai #1
Posted 02 December 2012 - 08:38 PM
I want to make this script do different things based on what the user inputs. For example, in this program if I were to enter "Alpha" as my password it would send a current to whatever is to the immediate right of the computer. Can this script be adapted to send a current to the left of the computer if I input "Bravo" as my password?


os.pullEvent = os.pullEventRaw
while true do
   term.clear()
   term.setCursorPos(1,1)
   print ("Door Status: Lock engaged")
   print ("Enter Password")
   write("Password:")
   UserInput = io.read()
   if UserInput == "Alpha" then
		  print ("Door lock disengaged")
		  rs.setOutput ("right", true )
		  sleep(5)
		  rs.setOutput ("right" , false )
   else
		  print ("Password incorrect, try again")
		  sleep(1)
   end
end

Could I just list some If statements like this?

if UserInput == "Alpha" then
print ("Right Side door unlocked")
if UserInput == "Bravo" then
print ("Toast")
if UserInput == "Charlie") then
print ("Entering alcohol induced coma")
sleep(9000)
end
end
end
zekesonxx #2
Posted 02 December 2012 - 09:14 PM

os.pullEvent = os.pullEventRaw
while true do
   term.clear()
   term.setCursorPos(1,1)
   print ("Door Status: Lock engaged")
   print ("Enter Password")
   write("Password:")
   UserInput = io.read()
   if UserInput == "Alpha" then
	  print ("Door lock disengaged")
	  rs.setOutput ("right", true )
	  sleep(5)
	  rs.setOutput ("right" , false )
   elseif UserInput == "Bravo" then
	  print ("Candy Machine lock disengaged")
	  rs.setOutput ("left", true )
	  sleep(5)
	  rs.setOutput ("left" , false )
   else
	  print ("Password incorrect, try again")
	  sleep(1)
   end
end
Nikolai #3
Posted 03 December 2012 - 07:36 AM
So can I add more elseif to expand the code further?
Bubba #4
Posted 03 December 2012 - 08:03 AM
So can I add more elseif to expand the code further?

There is no limit to the number of elseif statements you can make excepting too large a file, which is unlikely ever to happen to you. So yes, elseif is what you want in this case
Nikolai #5
Posted 03 December 2012 - 08:44 AM
One more question, I know that


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

will send a current through the red cable on the back of the computer. But how do I turn the current off?
Bubba #6
Posted 03 December 2012 - 08:59 AM
One more question, I know that


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

will send a current through the red cable on the back of the computer. But how do I turn the current off?

Just use rs.setBundledOutput("back", 0)
Nikolai #7
Posted 03 December 2012 - 09:09 AM
But wont that stop the current for all the wires connected to the back of the computer?
ChunLing #8
Posted 03 December 2012 - 09:35 AM
You were already doing that anyway. Or so I was about to say when I remembered that was about someone else today.

Okay, you can rs.setBundledOutput("back", colors.subtract(rs.getBundledOutput("back"),colors.red)) That should just turn off the red wire.
Nikolai #9
Posted 03 December 2012 - 09:39 AM
You were already doing that anyway. Or so I was about to say when I remembered that was about someone else today.

Okay, you can rs.setBundledOutput("back", colors.subtract(rs.getBundledOutput("back"),colors.red)) That should just turn off the red wire.
OK that's much better.