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

Password is always incorrect?

Started by AwesomePwningGuy, 04 November 2012 - 03:59 AM
AwesomePwningGuy #1
Posted 04 November 2012 - 04:59 AM
This is my code and I type in 1337, but it says incorrect.Help.


pass = 1337

print("Awesome Pwning Guy protected")
sleep(1)
print ("Enter password")
write "Password: "
input = read()
if input == pass then
print("Correct password")
sleep(1)
print("Access granted")
sleep(2)
redstone.setOutput("right", true)
sleep(4)
redstone.setOutout("right", false)
else
print("Password Incorrect")
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", true)
end


other error
After it goes incorrect it says

startup:20: attempt to call nil
Pharap #2
Posted 04 November 2012 - 05:15 AM
Already corrected this in my response to your other post, 1337 needs to be in " " quote marks. writing it as it is stores it as a number, the quote marks turn it into a 'string' (the programming equivalent of text) so:
pass = "1337"

Everything the user types into the console is treated as a 'string', so you need to store the password as a string.
brett122798 #3
Posted 04 November 2012 - 05:15 AM
The problem is, your password is an integer, it needs to be a string, so change this:


pass = 1337

To this:


pass = "1337"

The reason it needs to be a string is because your input is a string so 1337 does not equal "1337".

Next problem:


print("Password Incorrect")
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", true)

Change that to this:


print("Password Incorrect")
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", false) -- Changed to false
Pharap #4
Posted 04 November 2012 - 05:22 AM
The problem is, your password is an integer, it needs to be a string, so change this:


pass = 1337

To this:


pass = "1337"

The reason it needs to be a string is because your input is a string so 1337 does not equal "1337".

Next problem:


print("Password Incorrect")
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", true)

Change that to this:


print("Password Incorrect")
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", false) -- Changed to false

Something to remember when using the forums: don't copy directly from other people's posts, it copies that weird html-style code into your post, you need to paste it into notepad first, then cut that and paste it into your response. Putting it into notepad turns it into plain text and cuts out the font and colour stuff. Just a handy thing to know so it's easier to try and copy stuff from someone's post into your own.
brett122798 #5
Posted 04 November 2012 - 05:48 AM
The problem is, your password is an integer, it needs to be a string, so change this:


pass = 1337

To this:


pass = "1337"

The reason it needs to be a string is because your input is a string so 1337 does not equal "1337".

Next problem:


print("Password Incorrect")
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", true)

Change that to this:


print("Password Incorrect")
redstone.setOutput("left", true)
sleep(4)
redstone.setOutput("left", false) -- Changed to false

Something to remember when using the forums: don't copy directly from other people's posts, it copies that weird html-style code into your post, you need to paste it into notepad first, then cut that and paste it into your response. Putting it into notepad turns it into plain text and cuts out the font and colour stuff. Just a handy thing to know so it's easier to try and copy stuff from someone's post into your own.
I see that now, but I fixed it.
Pharap #6
Posted 04 November 2012 - 06:45 AM
Something to remember when using the forums: don't copy directly from other people's posts, it copies that weird html-style code into your post, you need to paste it into notepad first, then cut that and paste it into your response. Putting it into notepad turns it into plain text and cuts out the font and colour stuff. Just a handy thing to know so it's easier to try and copy stuff from someone's post into your own.
I see that now, but I fixed it.
Just a tip to keep in mind to avoid having to remove the excess the awkward way - manually.
remiX #7
Posted 04 November 2012 - 07:06 AM
He doesn't have to change pass = "1337"

He can just do this:

input = tonumber(read())
Pharap #8
Posted 04 November 2012 - 07:19 AM
He doesn't have to change pass = "1337"

He can just do this:

input = tonumber(read())

He could, but that's a complex solution to a simple problem. Besides, if he changes the password to something non-numerical, he'll have to remove the 'tonumber' and put the password in quote marks anyway.