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

[lua] Password at startup

Started by Beefy547, 11 July 2012 - 03:02 PM
Beefy547 #1
Posted 11 July 2012 - 05:02 PM
Help. I am lua-tarded and I am trying to make a password script on startup, it runs on startup, but doesn't work. I'm sure there are many things wrong with it so any help in pointing out the problems to me would be apriciated. Also I think it would be cool if when typing the password it turns them into *'s automaticly.


local pass = "smellys0cks"
term.clear()
term.serCursorPos(1,1)
print "Starting AndrewCraft3.0"
sleep(2)
print "Authentication Required"
write("Password= ")
input = read()
if input == pass then
term.clear()
term.serCursorPos(1,1)
print "Starting AndrewCraft3.0"
print "Authentication Required"
print "Password= ***********"
end
else
repeat
print "Password Incorrect"
write("password= ")
until input == pass then -- This is the part that I think is probably horribly wrong.
term.clear()
term.serCursorPos(1,1)
print "Starting AndrewCraft3.0"
print "Authentication Required"
print "Password= ***********"
end
OmegaVest #2
Posted 11 July 2012 - 05:11 PM
First, use read("*"). That will make anything typed in into *s.

Second, put all your ifs in one loop. I would use a while, but a repeat x until y works just as well. Then, when you detect the correct password, have it "break". That will exit the loop and continue the program normally from that point on.


By the way, this is in the tutorials. I just feel like being helpful this afternoon.
Beefy547 #3
Posted 11 July 2012 - 05:28 PM
I revised the script but upon reboot I get the following: [string "startup"]:14: <eof> expected.

The revised script:

local pass = "smellys0cks"
local i = 1
term.clear()
term.serCursorPos(1,1)
print "Starting AndrewCraft3.0"
sleep(2)
print "Authentication Required"
write("Password= ")
input = read("*")
if input == pass then
end
else
while i == "1" do
print "Password Incorrect"
write("password= ")
input = read("*")
if input == pass then break
end
Grim Reaper #4
Posted 11 July 2012 - 05:30 PM
Try enclosing your
print
statement with parenthesis :)/>/>


Your code:

print "Password Incorrect"

Revised code:

print("Password Incorrect")

Print is a function and therefore requires arguments. Lua receives arguments within brackets when you call the respective function.
OmegaVest #5
Posted 11 July 2012 - 05:34 PM
You put your else outside your if tree.

It goes:
If
Elseif
..
Else
End


And if you want to have a set amount of tries, you can make i into tries, make it a number like 2, and have it decrement at the end of the loop.



<EOF> means End Of File. When you see it, you have missed an End somewhere. It's like close-parens hell for Lua.



EDIT: Good lord Mystic types fast.
MysticT #6
Posted 11 July 2012 - 05:35 PM
Try enclosing your
print
statement with parenthesis :)/>/>


Your code:

print "Password Incorrect"

Revised code:

print("Password Incorrect")

Print is a function and therefore requires arguments. Lua receives arguments within brackets when you call the respective function.
Not really needed with just one argument.

Fixed code:

local pass = "smellys0cks"

while true do -- infinite loop
  term.clear() -- clear the screen
  term.serCursorPos(1,1)
  print("Starting AndrewCraft3.0")
  sleep(2)
  print("Authentication Required")
  write("Password= ")
  local input = read("*")
  if input == pass then -- if the password is correct
    break -- break the loop, end the program
  else -- if it's not
    print("Password Incorrect") -- say it's wrong
    sleep(1) -- wait some time and then start over (because of the loop)
  end
end
You should add Ctrl-T protection.
Beefy547 #7
Posted 11 July 2012 - 06:03 PM
@MysticT
After copying your code word for word i get startup:5: attempt to call nil.
MysticT #8
Posted 11 July 2012 - 06:04 PM
Derp, a simple typo:

term.serCursorPos(1, 1)
should be:

term.setCursorPos(1, 1)
LucasUK #9
Posted 11 July 2012 - 06:09 PM
Hey again Beefy,

Fixed his code, there was a slight typo, however:


Your error message states: startup:5: attempt to call nil.

If you read the code on the line number 5 (If you open it in notepad++ which is free it shows line numbers) you could see the typo for yourself.

Attempt to call nil means it tried to run a function, in this case:

term.serCursorPos(1,1)

However it was nil as this function does not exist, there is a function however for

term.setCursorPos(1,1)

Hopefully this may assist you with problems in the future :)/>/>



local pass = "smellys0cks"
while true do -- infinite loop
  term.clear() -- clear the screen
  term.setCursorPos(1,1)
  print("Starting AndrewCraft3.0")
  sleep(2)
  print("Authentication Required")
  write("Password= ")
  local input = read("*")
  if input == pass then -- if the password is correct
	break -- break the loop, end the program
  else -- if it's not
	print("Password Incorrect") -- say it's wrong
	sleep(1) -- wait some time and then start over (because of the loop)
  end
end
Beefy547 #10
Posted 11 July 2012 - 06:31 PM
Thanks MysticT it worked and LukasUK, I actually was using Notepad++ but after looking at the string for a couple minutes I couldn't tell it was a typo. Nice to see you again too LukasUK.
AnDwHaT5 #11
Posted 09 November 2012 - 02:44 AM
ok i looked at your code and i modified the modified code on one of your replies. the reason you get the error <eof> means there are to many ends at a peculair line. look at the line first and fix it. if you want to add a anti termination code near the top enter os.pullEvent = os.pullEventRaw. that stops ctrl and t.






local pass = "smellys0cks"
local i = 1
term.clear()
term.serCursorPos(1,1)
print "Starting AndrewCraft3.0"
sleep(2)
print "Authentication Required"
write("Password: ")
input = read("*")
if input == pass then
print("Password accepted!")
else
print "Password Incorrect"
sleep(1)
os.reboot()
end





or with the ctrl and t anti terminating.


os.pullEvent = os.pullEventRaw
local pass = "smellys0cks"
local i = 1
term.clear()
term.serCursorPos(1,1)
print "Starting AndrewCraft3.0"
sleep(2)
print "Authentication Required"
write("Password: ")
input = read("*")
if input == pass then
print("Password accepted!")
else
print "Password Incorrect"
sleep(1)
os.reboot()
end








im still new but im glad i can help with your issue completly. :P/>/>
remiX #12
Posted 09 November 2012 - 02:47 AM
Why are you replying on a 4 Month old thread :X
golinux #13
Posted 19 July 2013 - 01:42 AM
ctrl+t this will kill that program