Difference between revisions of "Read"

From ComputerCraft Wiki
Jump to: navigation, search
(Undo revision 3231 by 95.34.42.242 (talk))
(Change example.)
Line 14: Line 14:
 
{{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 (input == password) then
+
  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

Revision as of 18:12, 30 September 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.