Difference between revisions of "Read"

From ComputerCraft Wiki
Jump to: navigation, search
(YjEVQDKWhPzv)
(Undo revision 4605 by 168.215.243.4 (talk))
Line 1: Line 1:
in search just type in full name or  in the  frdeins button (next to the word facebook looks like 2 people) click on that then  find friend which is to the right up the top but this way is more friend of frdeins
+
{{lowercase}}
 +
{{Function
 +
|name=read
 +
|args= [[char (type)|char]] to replace userinput with
 +
|api=
 +
|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]]

Revision as of 13:44, 4 December 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

Examples

Grid paper.png  Example
Prints what the user wrote.
Code
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 '*'.
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.