Difference between revisions of "Read"

From ComputerCraft Wiki
Jump to: navigation, search
(Undo revision 3593 by (talk))
m (Moved to CAT:Tutorials.)
Line 27: Line 27:

Revision as of 15:47, 28 November 2012

Grid Redstone.png  Function read
Lets you get input of the user.
Syntax read(char to replace userinput with)
Returns nil
Part of ComputerCraft
API none


Grid paper.png  Example
Prints what the user wrote.
print (read())
Output Whatever the user wrote.

Grid paper.png  Example
Ask for a Password and lets the user enter it. The letters are hidden by '*'.
local password = "computercraft"
print ("Enter Password")
local input = read("*")
if input == password then
 print("Password is correct. Access granted.")
 print("Password is incorrect. Access denied.")
Output Enter Password


Password is correct. Access granted. or Password is incorrect. Access denied.