Textutils API

Textutils.complete

Functiontextutils.formatTime
Formats time (in ticks) in a human-readable format such as "6:30 PM". If twentyFourHour is set to true, the AM/PM prefix is omitted, and the time is presented in a 24-hour format such as "18:30".
Syntax textutils.formatTime(
  • time : number
  • twentyFourHour? : boolean
)
Returns string
Part of CC:Tweaked (source)
API textutils
ExampleWith 12-hour format
Prints the Minecraft world time in a 12-hour human-readable format.
Code
<nowiki>
print(textutils.formatTime(os.time()))
    </nowiki>
Output Depends on the world time, for example "6:30 PM".
ExampleWith 24-hour format
Prints the Minecraft world time in a 24-hour human-readable format.
Code
<nowiki>
print(textutils.formatTime(os.time(), true))
    </nowiki>
Output Depends on the world time, for example "18:30".

Textutils.pagedPrint Textutils.pagedTabulate

Functiontextutils.serialise
Converts value to a string representing it, which may be converted back to a value of the original type using textutils.unserialise.
Syntax textutils.serialise(
  • value : any
)
Returns string
Part of CC:Tweaked (source)
API textutils
ExampleSerialising a table
Prints a string representation of the given table.
Code
<nowiki>
print(textutils.serialise({ 1, 2, foo = "bar", baz = { 1, 2, 3 } })
    </nowiki>
Output
<nowiki>
{
  1,
  2,
  baz = {
    1,
    2,
    3,
  },
  foo = "bar"
}
</nowiki>
ExampleSaving a table to a file
Converts the given table to a string representing it, stores it in a file, then reads it back.
Code
<nowiki>
local t = { 1, 2, 3 }
print(t[1])
local f = fs.open("foo", "w")
f.write(textutils.serialise(t))
f.close()

local f = fs.open("foo", "r")
local t2 = textutils.unserialise(f.readAll())
f.close()
print(t2[1])
    </nowiki>
Output 1 1

Textutils.serialiseJSON

Functiontextutils.slowPrint
Slowly prints text, character-by-character, at the current cursor position in the current term. Accepts an optional rate parameter, in characters per second (default 20). This function is similar to textutils.slowWrite, however it automatically moves to the next line after writing.
Syntax textutils.slowPrint(
  • text : string
  • rate? : number
)
Returns nil
Part of CC:Tweaked (source)
API textutils
See also textutils.slowWrite
ExampleWith default rate
Slowly prints "Hello, world!" to the current term.
Code
<nowiki>
textutils.slowPrint("Hello, world!")
    </nowiki>
ExampleWith custom rate
Slowly prints "Hello, world!" to the current term, at 5 characters per second.
Code
<nowiki>
textutils.slowPrint("Hello, world!", 5)
    </nowiki>
Functiontextutils.slowWrite
Slowly writes text, character-by-character, at the current cursor position in the current term. Accepts an optional rate parameter, in characters per second (default 20). This function does not automatically move to the next line after writing.
Syntax textutils.slowWrite(
  • text : string
  • rate? : number
)
Returns nil
Part of CC:Tweaked (source)
API textutils
See also textutils.slowPrint
ExampleWith default rate
Slowly writes "Hello, world!" to the current term.
Code
<nowiki>
textutils.slowWrite("Hello, world!")
    </nowiki>
ExampleWith custom rate
Slowly writes "Hello, world!" to the current term, at 5 characters per second.
Code
<nowiki>
textutils.slowWrite("Hello, world!", 5)
    </nowiki>

Textutils.tabulate

Functiontextutils.unserialise
Converts a serialised string to a reassembled Lua value - the opposite of textutils.serialise. Returns nil if the unserialisation failed.
textutils.unserialise is implemented using load (source). It is loaded with an empty environment, therefore strings passed to textutils.unserialise cannot cause any harm to the computer. However, they can cause an infinite loop and cause the computer to crash for failing to yield!
Syntax textutils.unserialise(
  • serialisedValue : string
)
Returns any
Part of CC:Tweaked (source)
API textutils
ExampleDeserialising a serialised table
Prints a value of the given serialised table.
Code
<nowiki>
local serialised = "{ foo = \"bar\", fruit = \"apple\", colour = \"yellow\" }"
print(textutils.unserialise(serialised).fruit)
    </nowiki>
Output
<nowiki>
apple
</nowiki>

Textutils.urlEncode

This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.