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

My Unlock Door Program Help...

Started by Bladedemon70, 26 February 2012 - 07:16 PM
Bladedemon70 #1
Posted 26 February 2012 - 08:16 PM
I'm doing my first program which is a doorlock system beacuse it seemed easy to start….
well I'm doing a complicated one i guess or at least a little more fancy…

Error:
[string "Terminal" :73: '<eof>' expected]
Complete error line^^^^

Anyother help or condensing is welcome since it can be quite expanded due to the noobiness of myself….
Original Code: (Full of Errors)
Spoiler

--Unlocking Door Terminal
--Username
User = "Admin" --Set Desired Username
--Password
Pass = "Pass" --Set Desired Password
function clearload()
term.setCursorPos(1,2)
term.clear()
term.setCursorPos(1,1)
end
function clearall()
term.setCursorPos(1,1)
term.clear()
end
-- Running/ Turning on
clearall()
term.setCursorPos(15,1)
print ("{-- Terminal Lock V: 1.1 --}")
term.setCursorPos(1,3)
print ("Welcome User")
sleep(1.5) --Act likes its loading
term.setCursorPos(1,5)
print ("Loading....")
sleep(5)
term.setCursorPos(1,7)
print ("Loading Some Moar....")
sleep(5)
clearload()
term.setCursorPos(15,1)
print ("{-- Terminal Lock V: 1.1 --}")
--Entering in UserName and Password
print ("Enter Username")
read()
  if input == "User" then
   term.setCursorPos(1,3)
   print ("Welcome, [User]")
   term.setCursorPos(1,5)
   print ("Enter Correct Password Please")
	read()
	 if input == "Pass" then
	  term.setCursorPos(1,7)
	  print ("Correct...")
	  print ("Please Enter.")
	  sleep (2)
	  redstone.setOutput("back", true)
	  sleep (3)
	  redstone.setOutput("back", false)
	 else
	  print ("Incorrect Password")
	  sleep(1.5)
	  print ("Locking down terminal")
	  sleep(1)
	  print ("Goodbye")
	  sleep(1)
	  os.Reboot()
	 end
  else
   print ("Username not logged in system")
   sleep (1.5)
   print ("Locking down terminal")
   sleep(1)
   print ("Goodbye")
   sleep(1)
   os.Reboot()
  end
end
end

New Code
Spoiler

--Unlocking Door Terminal
--Username
User = "Admin" --Set Desired Username
--Password
Pass = "Pass" --Set Desired Password
function clearload()
term.setCursorPos(1,2)
term.clear()
term.setCursorPos(1,1)
end
function clearall()
term.setCursorPos(1,1)
term.clear()
end
-- Running/ Turning on
clearall()
term.setCursorPos(15,1)
print ("{-- Terminal Lock V: 1.1 --}")
term.setCursorPos(1,3)
print ("Welcome User")
sleep(1.5) --Act likes its loading
term.setCursorPos(1,5)
print ("Loading....")
sleep(5)
term.setCursorPos(1,7)
print ("Loading Some Moar....")
sleep(5)
clearload()
term.setCursorPos(15,1)
print ("{-- Terminal Lock V: 1.1 --}")
--Entering in UserName and Password
print ("Enter Username")
read()
  if input == User then
   term.setCursorPos(1,3)
   print ("Welcome, [User]")
   term.setCursorPos(1,5)
   print ("Enter Correct Password Please")
	read()
	 if input == Pass then
	  term.setCursorPos(1,7)
	  print ("Correct...")
	  print ("Please Enter.")
	  sleep (2)
	  redstone.setOutput("back", true)
	  sleep (3)
	  redstone.setOutput("back", false)
	 else
	  print ("Incorrect Password")
	  sleep(1.5)
	  print ("Locking down terminal")
	  sleep(1)
	  print ("Goodbye")
	  sleep(1)
	  os.Reboot()
	 end
  else
   print ("Username not logged in system")
   sleep (1.5)
   print ("Locking down terminal")
   sleep(1)
   print ("Goodbye")
   sleep(1)
   os.Reboot()
  end

And thanks to anyone who can help or will put input towards the code :D/>/>

[Edit]
Put new code in with fixes to the <eof> error
Liraal #2
Posted 26 February 2012 - 08:19 PM
It's simple: 2 'end's too much. I saw an API with loading bar on the forum that you may use as well.
Bladedemon70 #3
Posted 26 February 2012 - 08:44 PM
Ok thanks

that fixed i ran it through and i get caught up at the point to make it where i type in the username and it just goes to the else when i type it right

also what would it be to make the computer shutdown if it is wrong
Liraal #4
Posted 26 February 2012 - 08:54 PM
os.shutdown()
Bladedemon70 #5
Posted 26 February 2012 - 09:43 PM
Thanks again, Liraal.

Now the only problem is reading the input its wrong or something…. it just goes to else no matter the input
Espen #6
Posted 26 February 2012 - 09:56 PM
Thanks again, Liraal. Now the only problem is reading the input its wrong or something…. it just goes to else no matter the input
You're checking input for what was entered by the user, but you never assign input with read().
Replace both read() lines with this:
local input =  read()
This way what the user enters is not just vanishing in the void, but is actually stored inside the variable input. :D/>/>
Bladedemon70 #7
Posted 26 February 2012 - 10:08 PM
Ok wow thanks Espen…

and the last thing is the print line:
print ("Welcome, [User]")

This isn't right ofcourse… but how would you write it to make it say Welcome, {watever the username is set to}

would it be a local or something different
Liraal #8
Posted 26 February 2012 - 10:16 PM
print("Welcome, "..User)

you were close :D/>/>
Bladedemon70 #9
Posted 26 February 2012 - 10:23 PM
Dangit…….well thank you again Liraal
Bladedemon70 #10
Posted 26 February 2012 - 11:02 PM
Ok so i am trying to implement the loading/progress bar by xgaarocha

link for the function:
http://www.computerc...__fromsearch__1

Im am running into the phrase of "attempt to call string" when i enter the username in….

Current Code:
Spoiler

--Unlocking Door Terminal
--Username
User = "Admin" --Set Desired Username
--Password
Pass = "Pass" --Set Desired Password
function clearload()
term.setCursorPos(1,2)
term.clear()
term.setCursorPos(1,1)
end
function clearall()
term.setCursorPos(1,1)
term.clear()
end
--Loadbar function (Thanks to xgaarocha)
--Link: http://www.computercraft.info/forums2/index.php?/topic/180-gaas-useful-functions/page__hl__loading__fromsearch__1
function loadbar(s, char, size)
	-- Define parameters
	s = s or 10
	size = size or 10
	char = char or "~"
	local xpos,ypos = term.getCursorPos()
	local delay = s/size
	local start = 1
	while start < size  do
	term.setCursorPos(start, ypos)
	print (char)
	sleep(delay)
	start = start + 1
end
end

-- Running/ Turning on
clearall()
term.setCursorPos(13,1)
print ("{-- Terminal Lock V: 1.1 --}")
term.setCursorPos(1,3)
print ("Welcome User")
sleep(1.5) --Act likes its loading
term.setCursorPos(1,5)
loadbar(s, char, size)
sleep(5)
clearload()
term.setCursorPos(13,1)
print ("{-- Terminal Lock V: 1.1 --}")
--Entering in UserName and Password
print ("Enter Username")
local input = read()
  if input == User then
   term.setCursorPos(1,3)
   print ("Welcome, "..User".")
   term.setCursorPos(1,5)
   print ("Enter Correct Password Please")
	local input = read()
	 if input == Pass then
	  term.setCursorPos(1,7)
	  print ("Correct...")
	  print ("Please Enter.")
	  sleep (2)
	  redstone.setOutput("back", true)
	  sleep (5)
	  redstone.setOutput("back", false)
	  print ("Have a nice day")
	  sleep(1.5)
	  os.reboot()
	 else
	  print ("Incorrect Password")
	  sleep(1.5)
	  print ("Locking down terminal")
	  sleep(1)
	  print ("Goodbye")
	  sleep(1)
	  os.reboot()
	 end
  else
   print ("Username not logged in system")
   sleep (1.5)
   print ("Locking down terminal")
   sleep(1)
   print ("Goodbye")
   sleep(1)
   os.reboot()
  end
Espen #11
Posted 26 February 2012 - 11:06 PM
Try to replace …
print ("Welcome, "..User".") 
…with…
print ("Welcome, "..User..".") 
… for proper concatenation.
Bladedemon70 #12
Posted 27 February 2012 - 01:03 AM
Thanks again also Espen
schrolock #13
Posted 29 February 2012 - 05:32 PM
i cannot log in. Whats the username?
Bladedemon70 #14
Posted 01 March 2012 - 04:14 AM
Admin because the User var is set to Admin

its at the top of the code

Username
User = "Admin" Set Desired Username <– this is where the username is and set to the generic "Admin" but can be editted to something more personal

Password
Pass = "Pass" Set Desired Password <– as for this also can be set and this is the password

Keynote: They have to be typed to a 't' otherwise itll read it as wrong because "admin" is different than "Admin"
Also ignore the "" just type what is inside them