Difference between revisions of "Read"
From ComputerCraft Wiki
(Volume Pills Reviews: The reason why This Product Is truly Men'utes Favourite) |
(Add auto complete argument to accepted argument list) |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | + | {{lowercase}} | |
− | + | {{Function | |
− | + | |name=read | |
− | + | |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= | |
− | + | |returns=[[string (type)|string]] The user's input | |
− | + | |addon=ComputerCraft | |
− | + | |desc=Lets you get input of the user. | |
− | + | |examples= | |
− | + | {{Example | |
− | + | |desc=Prints what the user wrote. | |
+ | |code=[[print]] (read()) | ||
+ | |output=Whatever the user wrote. | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=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 | ||
+ | <nowiki>*******</nowiki> | ||
+ | Password is correct. Access granted. or Password is incorrect. Access denied. | ||
+ | }} | ||
+ | }} | ||
+ | |||
+ | [[Category:Tutorials]] |
Latest revision as of 17:26, 24 August 2016
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 |
Examples
Example | |
Prints what the user wrote. | |
Code |
print (read()) |
Output | Whatever the user wrote. |
Example | |
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. |