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

Start Computer With A Password

Started by Bennievv, 26 February 2012 - 11:29 AM
Bennievv #1
Posted 26 February 2012 - 12:29 PM
This is a script that locks your computer!

Type in the console:

edit startup
and type this code:

local funtion clearScreen()
term.clear()
term.setCursorPos(1,1)
end
while true do
clearScreen()
print("Welcome at ««YOUR NAME»» computer")
write"Password: "
if read("*") == "««PASSWORD»»" then
print("Correct password!")
sleep(1)
clearScreen()
shell.run("shell")
else
print("Incorrect password!")
sleep(2)
os.shutdown()
end
end

NOTE: You have to change ««YOUR NAME»» in your username and««PASSWORD»» into your password.

Another question:
Do anybody know how I can exit a program to the terminal
Liraal #2
Posted 26 February 2012 - 12:59 PM

return true
Bennievv #3
Posted 26 February 2012 - 01:05 PM

return true
:D/>/>
luza #4
Posted 26 February 2012 - 01:40 PM
you can easily bypass it by using ctrl + t.
Bennievv #5
Posted 26 February 2012 - 01:54 PM
you can easily bypass it by using ctrl + t.
Okay! :D/>/>
Espen #6
Posted 26 February 2012 - 03:34 PM
 return true 
That only works though if you call that from within the main program's scope, outside of any functions.
Or else your function will just return back to your main program.

If you're not planning on doing any exception handling in the future, then you could use a quick'n'dirty method and just throw an error wherever you want to exit your program:

function one( someVariable )
  -- Do something
  if someConditionIsMet then
	error("Program stopped ;-)")
  end
end

-- Main loop
while true do
  -- Do something
  one( someVariable )
end
arjag #7
Posted 21 January 2013 - 02:48 PM
gosh, took me way to long to spot the typo at the top where it says "funtion" instead of "function"


else
print("Incorrect password!")
sleep(2)
clearScreen()
sleep(4)
os.reboot()
end
end

I changed the end to this to make it reboot with a short delay instead of shutdown.
SuicidalSTDz #8
Posted 21 January 2013 - 03:32 PM
I suggest adding os.pullEvent = os.pullEventRaw to the first line of your code to prevent termination. Other than that it looks like you are off to a good start with Lua!
Cruor #9
Posted 22 January 2013 - 01:48 AM
Oh no! The necromancers are back D:
Locked to prevent the black magic from spreading.