API

This API Reference Manual documents all of classes, enumerations, data types, services, event, callbacks, and properties developers use while creating there game universes.

BrickVerse Globals

Functions

function , table pairs ( table t )

Returns an iterator function, the passed table t and nil, so that the construction will iterate over all key/value pairs of that table when used in a generic for-loop:

local scores = { ["John"] = 5, ["Sally"] = 10 }

for name, score in pairs(scores) do   
   print(name .. " has score: " .. score) -- "John has score: 5" etc
end

bool , Variant pcall ( function func, Tuple args )

Calls the function func with the given arguments in protected mode. This means that any error inside func is not propagated; instead, pcall catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, pcall also returns all results from the call, after this first result. In case of any error, pcall returns false plus the error message.

void print ( Tuple params )

Receives any number of arguments, and prints their values to the output. print is not intended for formatted output, but only as a quick way to show a value, typically for debugging. For a formatted output, use string.format. On BrickVerse, print does not call tostring, but will metatables for the the __tostring metamethod.

Variant loadstring ( string contents )

Loads Lua code from a string, and returns it as a function. This cannot load the binary version of Lua using loadstring.

Variant require ( ModuleScript module )

Runs the supplied ModuleScript if it has not been run already, and returns what the ModuleScript returned (in both cases).

If the ModuleScript the user wants to use has been uploaded to BrickVerse (with the instance’s name being ‘MainModule’), it can be loaded by using the require function on the asset ID of the ModuleScript, though only on the server.

string typeof ( Variant object )

Returns the type of the object specified, as a string. This function is more accurate than Lua’s native type function, as it does not denote BrickVerse-specific types as userdata.

number , number wait ( number seconds = 0.03 )

Yields the current thread until the specified amount of seconds have elapsed. The delay will have a minimum duration of 29 milliseconds, but this minimum may be higher depending on the target framerate and various throttling conditions. If the seconds parameter is not specified, the minimum duration will be used. This function returns:

  • Actual time yielded (in seconds)

  • Total time since the software was initialized (in seconds)

void warn ( Tuple params )

Behaves identically to Lua’s print function, except the output is styled as a warning, with yellow text and a timestamp. This function accepts any number of arguments, and will attempt to convert them into strings which will then be joined together with spaces between them.

void delay ( number delayTime, function callback )

Schedules a function to be executed after delayTime seconds have passed, without yielding the current thread. This function allows multiple Lua threads to be executed in parallel from the same stack. The delay will have a minimum duration of 29 milliseconds, but this minimum may be higher depending on the target framerate and various throttling conditions. If the delayTime parameter is not specified, the minimum duration will be used.

string tostring ( Variant e )

Receives an argument of any type and converts it to a string in a reasonable format. For complete control of how numbers are converted, use string.format. If the metatable of e has a __tostring metamethod, then it will be called with e as the only argument and will return the result.

local isBrickVerseCool = true
-- Convert the boolean to a string then concatenate:
print("BrickVerse is cool: " .. tostring(isBrickVerseCool)) --> BrickVerse is cool: true

Variant tonumber ( Variant arg, int base = 10 )

Attempts to convert the arg into a number with a specified base to interpret the value in. If it cannot be converted, this function returns nil.

The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter ‘A’ (in either upper or lower case) represents 10, ‘B’ represents 11, and so forth, with ‘Z’ representing 35. In base 10 (the default), the number may have a decimal part, as well as an optional exponent part. In other bases, only unsigned integers are accepted.

If a string begins with “0x” and a base is not provided, the 0x is trimmed and the base is assumed to be 16, or hexadecimal.

print(tonumber("1337")) --> 1337 (assumes base 10, decimal)
print(tonumber("1.25")) --> 1.25 (base 10 may have decimal portions)
print(tonumber("3e2")) --> 300 (base 10 may have exponent portion, 3 × 10 ^ 2)
print(tonumber("25", 8)) --> 21 (base 8, octal)
print(tonumber("0x100")) --> 256 (assumes base 16, hexadecimal)
print(tonumber("brickverse")) --> nil (does not raise an error)-- Tip: use with assert if you would like unconvertable numbers to raise an error
print(assert(tonumber("brickverse"))) --> Error: assertion failed

Variant assert ( Variant value, string errorMessage = assertion failed! )

Throws an error if the provided value is false or nil. If the assertion passes, it returns all values passed to it.

local product = 90 * 4
assert(product == 360, "Oh dear, multiplication is broken")-- The line above does nothing, because 90 times 4 is 360

Variant collectgarbage ( string operation )

Performs an operation on the Lua garbage collector based on the specified option.

BrickVerse's Lua sandbox only allows the “count” option to be used, so none of the other standard options are available.

The “count” option returns the total memory in use by Lua (in kilobytes).

void error ( string message, int level = 1 )

Terminates the last protected function called and outputs message as an error message. If the function containing the error is not called in a protected function (pcall), then the script which called the function will terminate. The error function itself never returns and acts like a script error.

The level argument specifies how to get the error position. With level 1 (the default), the error position is where the error function was called. Level 2 points the error to where the function that called error was called; and so on. Passing a level 0 avoids the addition of error position information to the message.

Variables

string _VERSION

A global variable (not a function) that holds a string containing the current interpreter version.

A reference to the DataModel, which is the root Instance of BrickVerse parent/child hierarchy.

DataModel Scene

A reference to the DataModel, which is the root Instance of BrickVerse streamed parts under Universe.

A reference to the script object that is executing the code you are writing. It can be either a ServerScript, a ClientScript, or a ModuleScript and sometimes a CoreScript.

This variable is not available when executing code from BrickVerse Studio’s command bar.

array shared

table that is shared between all scripts of the same context level. Only shared across same authority level, for example it can't go across client -> server / server -> client. Only server -> server / client -> client.

A table that is shared between all scripts of the same context level. Same as _shared.

Bool IsCoreScript

Boolean variable if it's a corescript. Variable can be set, however it has no affect.

Lua Globals

pagemath

Last updated