write

From ComputerCraft
Jump to: navigation, search

write
Function
Syntax
write()
Returns number linesPrinted
API BIOS globals
Source CC:Tweaked (source)

Writes text at the current cursor position in the current term. Unlike print, this function does not automatically move to the next line after writing, however it does perform text wrapping, meaning if the string is too big for the term, it will continue writing on the next line. write returns the number of extra lines it printed (i.e. if it did not need to wrap to the next line, it will return 0).

  • ☒N This function will not insert a newline after printing.
  • ☒N This function does not support printing multiple objects. You will have to concatenate them together into a single string.
  • ☑Y This function supports writing newlines (e.g. via the \n character).
  • ☑Y This function will wrap the text when it is longer than the screen width.
  • If you don't want a trailing newline, or would like to print multiple objects, consider using print instead.
  • If you would like lower level access to the terminal object, consider using term.write instead.
ExampleExampleWrite to the term
Writes "Hello, world!" to the current term.
Code
write("Hello, world!")
Output
Hello, world!
ExampleExampleWrite multiple strings the term
Writes "foobar" to the current term. Note how there is no space between writes.
Code
write("foo")
write("boo")
Output
foobar
ExampleExampleWrite a very long string
Writes "foo" to the current term 50 times. Note how it automatically wraps to the next line where necessary.
Code
write(("foo "):rep(50))
Output Demo write multiple.png