Skip to main content

Misc Globals

Documentation for the various things Figura adds to the global lua state

warning

This page is a WIP. It contains all the information in Figura's documentation but we're working on adding more helpful descriptions.


figuraMetatables

A table containing all the metatables for Figura's object types

The metatables are editable


listFiles()

A function that returns a table with all script file names from the specified path

If no path is specified, it will fetch from the root folder

A second argument, boolean, can be given to also list files inside subfolders

Folders can be accessed relative to the executing script using ./ and ../

listFiles()

Returns:

TypeDescription
Table-

Example:

-- Using autoscripts in avatar.json,
-- you can prevent loading scripts by default and instead require them like so
for _, script in ipairs(listFiles("/scripts", true)) do
require(script)
end

parseJson()

Takes a JSON string as an argument, and converts it into a lua value.

Objects and arrays are converted to tables appropriately.

parseJson(jsonString)

Parameters:

NameTypeDescriptionDefault
jsonStringString--

Returns:

TypeDescription
AnyType-

Example:

function events.CHAT_RECEIVE_MESSAGE(msg, jsonStr)
local json = parseJson(jsonStr)
-- Gets the name of message sender
local sender = json.with[1].hoverEvent.contents.name.text
end

print()

Aliases: log()

A function that writes its arguments to chat

Even though the syntax says only one argument, you can put as many as you want

All of them will print, and they'll be separated by a tab space

Returns the string representation of all values

print(arg)

Parameters:

NameTypeDescriptionDefault
argVarargs--

Returns:

TypeDescription
String-

Example:

print("hello, world!")

print("Avatar:", avatar:getName())

printJson()

Aliases: logJson()

Takes a Minecraft JSON string as an argument, and prints it to the chat formatted, without the lua print header

Even though the syntax says only one argument, you can put as many as you want

All of them will print, and they'll be appended in the end of the previous argument

Returns the formatted string

printJson(json)

Parameters:

NameTypeDescriptionDefault
jsonString--

Returns:

TypeDescription
String-

Example:

local wikiAd = {
"",
{ text = "Learn more about Figura " },
{
text = "here",
underlined = true,
color = "aqua",
clickEvent = {
action = "open_url",
value = "https://wiki.figuramc.org",
}
},
{ text = ".\n" }
}

printJson(toJson(wikiAd))

printTable()

Aliases: logTable()

The first argument is either a Table, or it's a Userdata, which refers to any of the added Figura types

Prints the table out to chat, specially formatted

If userdata is passed in, it is automatically converted to a table or string, and displayed

In the case of tables inside of tables, the "maxDepth" parameter will be used to determine how far to go

Default value for maxDepth is 1

Third argument, "silent", will skip the chat print and will only return the string

printTable(table)

Parameters:

NameTypeDescriptionDefault
tableTable--

Returns:

TypeDescription
String-

Example:

printTable(textures:getTextures())

require()

The require() function takes the name of one of your scripts, without the .lua extension

If this script has not been already run before, it will run that script and return the value that script returns

If it has been run before, then it will not run the file again, but it will return the same thing as the first time

If a required script has no returns, then require() will return true

If the name you give isn't any of your scripts, it will error

Scripts can be accessed relative to the executing script using ./ and ../

require(scriptName)

Parameters:

NameTypeDescriptionDefault
scriptNameString--

Returns:

TypeDescription
AnyType-

Examples:

Script in root folder

MyCoolAvatar├─ script└─ JimmyAnims
-- script.lua
require("JimmyAnims")

Script in another folder

MyCoolAvatar├─ script└─ MyFolder   └─ GSAnimBlend
-- script.lua
require("MyFolder.GSAnimBlend")

toJson()

Aliases: toJson()

Takes any lua value, and converts it into a json string.

Does not accept functions, they will be treated as null.

toJson(value)

Parameters:

NameTypeDescriptionDefault
valueAnyType--

Returns:

TypeDescription
String-

Example:

nameplate.ALL:setText(
toJson({
text = "Wiki",
color = "#99BBEE",
})
)

type

Figura overrides lua's type() function

When used on Figura types, returns the type's name as seen in the docs and in the figuraMetatables global

When called on a table that has a metatable with a __type key, returns the corresponding value

Example:

type(2) -- number
type("foo") -- string
type(models) -- ModelPart
type(setmetatable({}, { __type = "MyType" })) -- MyType