6 posts
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
839 posts
Location
England
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.
295 posts
Location
In the TARDIS at an unknown place in time.
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
839 posts
Location
England
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.
295 posts
Location
In the TARDIS at an unknown place in time.
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.
839 posts
Location
England
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.
2088 posts
Location
South Africa
Posted 04 November 2012 - 07:06 AM
He doesn't have to change pass = "1337"
He can just do this:
input = tonumber(read())
839 posts
Location
England
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.