read

From ComputerCraft
Jump to: navigation, search

read
Function
Syntax
read()
Returns string textEntered
API BIOS globals
Source CC:Tweaked (source)

Reads a string of text at the current cursor position in the current term. typingCharacter will automatically be converted to a string using the tostring function. This function moves to the next line after the user presses enter. Optionally, typingCharacter can be specified so that the user's input is hidden and typingCharacter is written in each typed character's place. read returns the string the user entered. Using the history parameter, it is possible to provide a history of previous commands entered (as an array of strings), so that the user can use the up and down arrow keys to browse through them.

ExampleExampleRead a string of text
Reads a string of user entered text (`Hello World!`) in the current term, assigns it to a variable and then prints it.
Code
local userInput = read()
print(userInput)
Output
Hello World!
ExampleExampleRead a hidden string of text
Reads a string of user entered text (`Hello World!`) in the current term whilst keeping what the user is writing hidden (`************`), assigns it to a variable and then prints it.
Code
local userInput = read("*")
print(userInput)
Output
Hello World!