Difference between revisions of "Read"

From ComputerCraft Wiki
Jump to: navigation, search
m (Added history argument, clarified doesn't actually return 'nil'...)
(Add auto complete argument to accepted argument list)
Line 2: Line 2:
|args= <nowiki>[</nowiki> [[char (type)|char]] replacement <nowiki>[, </nowiki>[[table (type)|table]] history<nowiki>]</nowiki> <nowiki>]</nowiki>
|args= <nowiki>[</nowiki> [[char (type)|char]] replacement <nowiki>[, </nowiki>[[table (type)|table]] history <nowiki>[, </nowiki>[[function (type)|function]] auto complete <nowiki>]]</nowiki> <nowiki>]</nowiki>
|returns=[[string (type)|string]] The user's input
|returns=[[string (type)|string]] The user's input

Latest revision as of 17:26, 24 August 2016

Grid Redstone.png  Function read
Lets you get input of the user.
Syntax read([ char replacement [, table history [, function auto complete ]] ])
Returns string The user's input
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.