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

I'm not sure why this isn't working

Started by crazyjoe567, 11 April 2013 - 09:46 AM
crazyjoe567 #1
Posted 11 April 2013 - 11:46 AM
I have this bit of code but when it gets to the choice part it ignores the rest of the code and doesn't let me input a choice


y = colors.combine( colors.yellow )

r = colors.combine( colors.red )

rr = colors.subtract( colors.red )

yy = colors.subtract( colors.yellow )

term.clear()

–local pullEvent = os.pullEvent
–os.pullEvent = os.pullEventRaw
sfile = io.open("/startup", "w")
sfile:write('shell.run("door")')
sfile:close()
term.setCursorPos(1,1)
print(" ———–Giuseppe's Burgeria———–")
print("")
print("")
print("")
print(" Please Enter Your Password")
print(" Password:")
term.setCursorPos(20,6)
local input = read("*")
if input == "potato" then
term.clear()
term.setCursorPos(1,1)
sleep(1)
print(" ———–Giuseppe's Burgeria———–")
print("")
print("")
print("")
print(" 1.Open Main Doors")
print(" 2.Close Main Doors")
print("")
print(" 3.Open Farm Doors")
print(" 4.Close Farm Doors")
print("")
print(" 5.Logout")
print("")
term.setCursorPos(15,13)
if input == "1" then
rs.setBundledOutput( "down", y )
print("Open")
elseif input == "2" then
rs.setBundledOutput( "down", yy )
print("Closed")
elseif input == "3" then
rs.setBundledOutput( "down", r )
print("Open")
elseif input == "4" then
rs.setBundledOutput( "down", rr )
print("Closed")
elseif input == "5" then
os.reboot()
elseif input =="admin1" then
fs.delete("startup")
print(" auto start disabled")
sleep(1)
else
end
else
print(" Wrong Password")
sleep(1)
os.reboot()
end
QuantumGrav #2
Posted 11 April 2013 - 12:01 PM
You are only calling io.read() once, so input is equal to "potato" and you're asking if it's equal to some numbers.

Here's what you have:


term.setCursorPos(15,13)
if input == "1" then
--etc.

Here's what it should be:


term.setCursorPos(15,13)
input = io.read()
if input == "1" then
--etc.

That should work I think!

Also, I would suggest putting that amount of code into a code brick and also a spoiler. Just makes it nicer to read!
crazyjoe567 #3
Posted 11 April 2013 - 12:05 PM
Ok thanks I will try this!
crazyjoe567 #4
Posted 11 April 2013 - 12:08 PM
Also I put down instead of bottom again :/
crazyjoe567 #5
Posted 11 April 2013 - 12:11 PM
Also how do you loop the choice part so it only stops when I type 5
Kingdaro #6
Posted 11 April 2013 - 12:26 PM
Just wrap it in a while loop.

  while true do
    if input == "1" then
      rs.setBundledOutput( "down", y )
      print("Open")
    elseif input == "2" then
      rs.setBundledOutput( "down", yy )
      print("Closed")
    elseif input == "3" then
      rs.setBundledOutput( "down", r )
      print("Open")
    elseif input == "4" then
      rs.setBundledOutput( "down", rr )
      print("Closed")
    elseif input == "5" then
      break
    elseif input =="admin1" then
      fs.delete("startup")
      print("  auto start disabled")
      sleep(1)
    end
  end
crazyjoe567 #7
Posted 11 April 2013 - 12:33 PM
thanks