read

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.

ExampleRead 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
<nowiki>
local userInput = read()
print(userInput)
    </nowiki>
Output
Hello World!
ExampleRead 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
<nowiki>
local userInput = read("*")
print(userInput)
    </nowiki>
Output
Hello World!

read
Function
Syntax
read(
  • typingCharacter? : string
  • history? : table
  • completeFunction? : function
  • defaultText? : string
)

Returns string textEntered
API BIOS globals
Source CC:Tweaked (source)
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.