Difference between revisions of "Read"
From ComputerCraft Wiki
m |
(Add auto complete argument to accepted argument list) |
||
| (9 intermediate revisions by 7 users not shown) | |||
| Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=read | |name=read | ||
| − | |args= [[char (type)|char]] | + | |args= <nowiki>[</nowiki> [[char (type)|char]] replacement <nowiki>[, </nowiki>[[table (type)|table]] history <nowiki>[, </nowiki>[[function (type)|function]] auto complete <nowiki>]]</nowiki> <nowiki>]</nowiki> |
|api= | |api= | ||
| + | |returns=[[string (type)|string]] The user's input | ||
|addon=ComputerCraft | |addon=ComputerCraft | ||
|desc=Lets you get input of the user. | |desc=Lets you get input of the user. | ||
| Line 14: | Line 15: | ||
{{Example | {{Example | ||
|desc=Ask for a Password and lets the user enter it. The letters are hidden by '*'. | |desc=Ask for a Password and lets the user enter it. The letters are hidden by '*'. | ||
| − | |code=password = "computercraft" | + | |code=local password = "computercraft" |
[[print]] ("Enter Password") | [[print]] ("Enter Password") | ||
| − | input = read ("*") | + | local input = read("*") |
| − | if | + | if input == password then |
| − | [[print]] ("Password is correct. Access granted.") | + | [[print]]("Password is correct. Access granted.") |
else | else | ||
| − | [[print]] ("Password is incorrect. Access denied.") | + | [[print]]("Password is incorrect. Access denied.") |
end | end | ||
|output=Enter Password | |output=Enter Password | ||
| Line 27: | Line 28: | ||
}} | }} | ||
}} | }} | ||
| + | |||
| + | [[Category:Tutorials]] | ||
Latest revision as of 17:26, 24 August 2016
| 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 |
Examples
| Prints what the user wrote. | |
| Code |
print (read()) |
| Output | Whatever the user wrote. |
| Ask for a Password and lets the user enter it. The letters are hidden by '*'. | |
| Code |
local password = "computercraft" print ("Enter Password") local input = read("*") if input == password then print("Password is correct. Access granted.") else print("Password is incorrect. Access denied.") end |
| Output | Enter Password
******* Password is correct. Access granted. or Password is incorrect. Access denied. |