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

need help with some password coding

Started by doomman117, 11 July 2012 - 12:08 PM
doomman117 #1
Posted 11 July 2012 - 02:08 PM
ok so i am trying to make a password system and i am trying to make something that it hints me the password when i type in "hint" i get a error correct it but it gives me the same error. i will provide my code in the pastebin i REALLY need help with this guys!!! so please if you could edit the code and fix the error and tell me what i did wrong it would be great! thanks!!

PS- the error i get is [string "startup"}:18: 'end' expected (to close 'if' at line 17)

i don't know what it is talking about!!!!!

PASTEBIN: http://pastebin.com/q1yH6L26
MysticT #2
Posted 11 July 2012 - 03:05 PM
Mmm, I guess it was expecting an end, to close the if at line 17 :)/>/>
You need to close every if with an end. If syntax:

if <condition> then
end

if <condition> then
else
end

if <condition> then
elseif <condition2> then
else
end

Adding an end at the end of your program will make the error go away, but there's an error in the program's logic:
If the input equals the password, you say it's correct, and open the door.
If it's not, you say access denied, an shut down the computer.
It never gets to the last if.

Fixed code:

local pass = "tactics" -- added local, it's good practice to do it
local hint = "hint

print ("Welcome to Doomman117's House")
write("password: ")
local input = read()
if input == pass then
  print ("Welcome Doomman117")
  redstone.setOutput ("left", true) -- added missing quote here also (to close "left")
  sleep(2)
  os.shutdown()
elseif input == hint then
  write("Favorite PS1 Game")
else
  print ("Access Denied")
  sleep(2)
  os.shutdown()
end
You may want to have it in a loop instead of shuting down the computer. Right now, when you enter "hint" it will write "Favorite PS1 Game" and let you use the computer.
doomman117 #3
Posted 11 July 2012 - 03:44 PM
thank you very much! i am new to this and trying to find a error in this think is very hard XD thank you!!
doomman117 #4
Posted 11 July 2012 - 04:03 PM
ahhh sorry to jump to conclusions…afteri did the code and put ends where they should be i get this error

[string "startup"]:13: '<eof>' expected
MysticT #5
Posted 11 July 2012 - 04:52 PM
Post the new code, it looks like you have an extra end.
doomman117 #6
Posted 11 July 2012 - 05:04 PM
http://pastebin.com/8h0CL4zU
MysticT #7
Posted 11 July 2012 - 05:29 PM
This should work:

os.pullEvent = os.pullEventRaw -- prevent termination (Ctrl-T)

local pass = "tactics"
local hint = "hint"

while true do -- infinite loop, to keep the program running
  term.clear() -- clear the screen
  term.setCursorPos(1, 1)
  print ("Welcome to Doomman117's House")
  write("Password: ")
  local input = read("*")
  if input == pass then
	print ("Welcome Doomman117")
	rs.setOutput("left", true)
	sleep (2)
	rs.setOutput("left", false)
  elseif input == hint then
    print("Favorite PS1 Game")
	sleep(2)
  else
	print("Access Denied")
	sleep(2)
  end
end
doomman117 #8
Posted 11 July 2012 - 05:56 PM
ok i think we almost got it it says now "Attempt to write to global"
MysticT #9
Posted 11 July 2012 - 06:02 PM
If you'r using the code I posted above, make sure you typed it right, specially the os.pullEvent.
doomman117 #10
Posted 11 July 2012 - 06:17 PM
YAY :)/>/> thank you so very much!!!! if i need anything else do you have a skype i can contact you with?