Jump to content




I'm not sure why this isn't working


  • You cannot reply to this topic
6 replies to this topic

#1 crazyjoe567

  • Members
  • 11 posts

Posted 11 April 2013 - 10: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

#2 QuantumGrav

  • Members
  • 36 posts
  • LocationUnited States

Posted 11 April 2013 - 11:01 AM

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!

#3 crazyjoe567

  • Members
  • 11 posts

Posted 11 April 2013 - 11:05 AM

Ok thanks I will try this!

#4 crazyjoe567

  • Members
  • 11 posts

Posted 11 April 2013 - 11:08 AM

Also I put down instead of bottom again :/

#5 crazyjoe567

  • Members
  • 11 posts

Posted 11 April 2013 - 11:11 AM

Also how do you loop the choice part so it only stops when I type 5

#6 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 11 April 2013 - 11:26 AM

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


#7 crazyjoe567

  • Members
  • 11 posts

Posted 11 April 2013 - 11:33 AM

thanks





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users