Jump to content




Password door


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

#1 tysciman7

  • Members
  • 41 posts

Posted 28 January 2013 - 01:13 PM

I cant get this to work as soon as the first incorrect pass is typed it says the right text but then the program ends so if you can please help me



here it is

os.shutdown = os.shutdown
rednet.open("back")
os.pullEvent = os.pullEventRaw
local mon = peripheral.wrap("top")
i = 0
local alarm = false
local door = false
mon.clear()
mon.setTextScale(1)
mon.setCursorPos(1,1)
mon.write("Welcome to TyCo's")
mon.setCursorPos(1,3)
mon.write("CC store")
while door == false do
term.clear()
term.setCursorPos(14,1)
print("Welcome to Temporary Tyco")
term.setCursorPos(1,3)
term.write("Please Enter Password:")
pass = read("*")
if pass == "inside" then
term.setCursorPos(16,7)
print("Password Authorized")
redstone.setOutput("right", true)
sleep(5)
redstone.setOutput("right", false)
else
if pass == "computers" then
print("Welcome Admin")
door = true
else
if pass == "leave" then
redstone.setOutput("right", true)
sleep(5)
redstone.setOutput("right", false)
else
i = i + 1
while alarm == false do
if (i == 1) then
print("Incorrect 2 more trys")
alarm = true
end
if (i == 2) then
print("Incorrect 1 more try")
alarm = true
end
if (i == 3) then
print("Alarm Activated")
print("Administrator is being advised")
rednet.send(id, "alarm")
alarm = true
end
end
end
end
end
end

#2 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 28 January 2013 - 02:25 PM

Firstly, please use [ CODE] and [ /CODE] tags to surround your code, and please indent it to make it readable, so we can check if you're missing an end, etc...

I'll step through the code:

os.shutdown = os.shutdown accomplishes nothing. It has no effect on the code at all. It's like saying
local a = "hello"
a = a

And I also think you don't understand the concept of elseif. Here is an example:
var = "hello"
if var == "hello" then
  -- Will occur if var is equal to hello
elseif var == "not hello" then
  -- If var does not equal hello, and also equals "not hello", then this will execute
elseif var == "test" then
  -- If var does not equal any of the above, and var equals "test", this will execute
elseif var == "meh" then
  -- Again, if var does not equal any of the above, and var equals "meh", then this will execute
else
  -- If none of the above are true, then this will execute
end

So basically this:
else
  if pass == "computers" then
  -- Code here
Should be this:
elseif pass == "computers" then
  -- Code here

Next, you don't need that while loop at all in the else statement. You can make do without. You should also use elseif statements when checking i == 3, i == 2, etc...

Fixed code:
Spoiler


#3 tysciman7

  • Members
  • 41 posts

Posted 28 January 2013 - 03:59 PM

when i have one wrong password it says "2 more trys" (like it should) but then it breaks the program

#4 ChunLing

  • Members
  • 2,027 posts

Posted 28 January 2013 - 04:48 PM

Hmm...how did you copy the code into your computer?

Can you verify that each line containing an instance of the variable door is exactly as in the above post?

#5 tysciman7

  • Members
  • 41 posts

Posted 29 January 2013 - 08:49 AM

I type it all in since i do this on my friends server yeah I can check





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users