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

Plesae help me i'm a noob

Started by Kingsora, 18 July 2013 - 05:48 AM
Kingsora #1
Posted 18 July 2013 - 07:48 AM
I am new to computercraft and want to make a simple lock program.
I have edited startup and done this

shell.run("clear")

print("Please enter password")

password = read()

if password ~= "password" then
os.shutdown
else
print("correct")
redstone.setOutput("back", True)
sleep (5)
os.shutdown

I am getting this show up when i restart the computer

bios : 338 : [string "startup"] : 9 : '=' expected

What do i do to fix it?
Lyqyd #2
Posted 18 July 2013 - 01:06 PM
Split into new topic.

`os.shutdown` should be `os.shutdown()`. True should be true. You appear to be missing an `end`.
Zudo #3
Posted 18 July 2013 - 01:09 PM
Split into new topic.

`os.shutdown` should be `os.shutdown()`. True should be true. You appear to be missing an `end`.

Yes, and you might want to do read("*") to hide the password.

PS: surround your code with the
 tags plz!
BlockDriller #4
Posted 18 July 2013 - 03:32 PM

print("Please enter password")
password = read("*")
if password == "password" then
print("correct")
redstone.setOutput("back", true)
sleep (5)
os.shutdown()
else
os.shutdown()
end

That should work fine. Replace "password" with whatever you want the pass to be.

Also with your current code, if the password is entered correctly the computer will shutdown, if entered incorrectly it will unlock the computer. You need to swap the code below the else around. I fixed it though in my code. You may also want to clear the screen so it only shows enter password so I wrote a better version.


term.clear()
term.setCursorPos(1, 1)
print("Please enter password")
password = read("*")
if password == "password" then
print("correct")
redstone.setOutput("back", true)
sleep (5)
os.shutdown()
else
os.shutdown()
end

Enjoy.
apemanzilla #5
Posted 18 July 2013 - 04:10 PM

-snip-

That should work fine. Replace "password" with whatever you want the pass to be.

Also with your current code, if the password is entered correctly the computer will shutdown, if entered incorrectly it will unlock the computer. You need to swap the code below the else around. I fixed it though in my code. You may also want to clear the screen so it only shows enter password so I wrote a better version.


-snip-

Enjoy.
He used the "~=" operator (not equals), so it would've worked fine if the other errors were fixed.
golinux #6
Posted 19 July 2013 - 02:03 AM
this is my password program iits a little weird i have seen many ways of doing a password program but this one works just fine for me.


local y =1
local password

password = read()

while y==1 do
if password==("hello") then
print("correct password")
break
else
print("rong password")
password = read()
end
end