public static class Global

The functions that reside in the global scope.


function ObjectExists(object)

A safe way to check whether a wrapper isn't nil, and whether the underlying object hasn't been destroyed.

Arguments

Returns: (bool) Whether this wrapper exists, and whether the underlying object in it hasn't been destroyed.


function Enum(objects, offset)

Creates a new pseudo-enum class from the given objects and starting at the given offset.

Arguments

Returns: (table) The "enum" table. For example, local test = Enum({"First", "Second"}) would result in a table that has two elements named First and Second, with "test.First" being equal to 1 and "test.Second" being equal to 2.


worldGlobals = {}

The global table shared across all scripts.


function RunAsync(func)

Schedules a function to run as a coroutine. Coroutines are updated every game tick.

Arguments


function Wait(func)

Waits for either a function or an awaiter inside of a coroutine.

Arguments

Returns: (many) Whatever "func" is or whatever is the result of calling func(), if it is a function.


function Yield()

Yields the execution of this coroutine for this frame


function Frames(count)

Awaiter that waits for the given amount of frames.

Arguments


function Seconds(seconds)

Awaiter that waits for the given amount of seconds.

Arguments


function Event(eventName, evtEntity)

Awaiter that waits for an event to be signaled.

Arguments


function Until(func)

Awaiter that waits for a condition to return true.

Arguments


function ListenFor(evtName, evtCallback, evtEntity)

Creates a new event listener for a named event.

Arguments

Returns: (ListenerData) A table containing some information about this listener, allowing us to remove it later.


function RemoveEventListener(listenerInfo)

Removes a listener from the list of active listeners.

Arguments


function SignalEvent(evtName, evtPayload, evtEntity)

Signals an event.

Arguments


function RPC(name, side, reliability, callback)

Creates a new Remote Procedure Call. For this to work, it has to be registered both on the server and on the client.

Arguments


function CreateMicrogameVariation(name, onBeginMicrogame, onMicrogameTick, onPostMicrogame, rarity)

Creates a new microgame variation. All of the functions will be fired for both the client and the server.

Arguments

Returns: (table) A microgame variation data table.


function CreatePreparedMicrogameVariation(name, onPrepareMicrogame, onBeginMicrogame, onMicrogameTick, onPostMicrogame, rarity)

Same as CreateMicrogameVariation, with the addition of onPrepareMicrogame function.

Arguments

Returns: (table) A microgame variation data table.


function CreateMicrogame(name, musicArray, variationsArray, params)

Creates a microgame. Has to be called for every single client.

Arguments

Returns: (LuaMicrogame) The microgame


function SDBM(value)

(Client) Get the SDBM hash value of a string/byte sequence.

Arguments

Returns: (number) The hash.


function AddI18nToLocale(language, data)

Adds this I18n to be reloaded when a specific language loads.

Arguments


function RequestAvatar(player, callback)

Requests a player's avatar and returns it in a callback.

Arguments


public static string GetSessionVariable(string key)

(Client) Gets a Lua variable from the session store.

Arguments

Returns: (string) The value, or null if the value doesn't exist.


public static void SetSessionVariable(string key, string value)

(Client) Sets a Lua variable that lives for as long as MicroWorks is running.

Arguments


public static bool TryGetFromTable<T>(LuaTable tbl, string key, out T value)

Gets a value from a table if it exists.

Returns: Whether the value exists or not.


public static LuaTable Import(string path)

(Client) Imports a file from the VFS and returns its result.

Arguments

Returns: (table) The result from the execution.


public static XorShift MakePRNG(uint? seed = null)

(Client) Makes a XorShift PRNG.

Arguments

Returns: (XorShift) The PRNG.


public static LuaCastHit CastRay(LuaVector3 origin, LuaVector3 direction, float length)

(Client) Cast a ray from an origin point.

Arguments

Returns: (CastHit) A structure containing the hit information.


public static LuaTable CastRayAll(LuaVector3 origin, LuaVector3 direction, float length)

(Client) Cast a ray from an origin point, and return all objects that intersect the ray.

Can hold no more than 20 results.

Arguments

Returns: (LuaTable) A table of CastHit containing the hit information.


public static LuaCastHit CastSphere(LuaVector3 origin, LuaVector3 direction, float radius, float length)

(Client) Cast a sphere along a ray from an origin point. Think of it like a thick raycast.

Arguments

Returns: (CastHit) A structure containing the hit information.


public static LuaTable CastSphereAll(LuaVector3 origin, LuaVector3 direction, float radius, float length)

(Client) Cast a sphere along a ray from an origin point, and return all objects that intersect the sphere.

Can hold no more than 20 results.

Arguments

Returns: (LuaTable) A table of CastHit containing the hit information.


public static LuaTable CheckSphere(LuaVector3 origin, float radius)

(Client) Gets all game objects inside of a radius.

Can hold no more than 20 results.

Arguments

Returns: (LuaTable) A table of all gameobjects in provided radius.


public static LuaTable CheckSpherePlayers(LuaVector3 origin, float radius)

(Client) Gets all players inside of a radius.

Arguments

Returns: (LuaTable) A table of all players in provided radius.


public static bool CheckLine(LuaVector3 startPoint, LuaVector3 endPoint)

(Client) Checks if an object is intersecting between two points.

Arguments

Returns: (bool) Whether an object is intersecting the line between start and end point.


public static bool GetButton(string action)

(Client) Get the state of a bound button.

Arguments

Returns: (bool) If it's held or not.


public static bool GetButtonDown(string action)

(Client) Get whether a bound button was pressed down this frame.

Arguments

Returns: (bool) If it was pressed this frame.


public static bool GetButtonUp(string action)

(Client) Get whether a bound button was released this frame.

Arguments

Returns: (bool) If it was released this frame.


public static bool GetKey(int keyCode)

(Client) Get the state of a key.

Arguments

Returns: (bool) If it's held or not.


public static bool GetKeyDown(int keyCode)

(Client) Get whether a key was pressed down this frame.

Arguments

Returns: (bool) If it was pressed this frame.


public static bool GetKeyUp(int keyCode)

(Client) Get whether a key was released this frame.

Arguments

Returns: (bool) If it was released this frame.


public static int GetPlayedGames()

(Client) Gets the amount of games the local user has played.

Returns: (int) The amount of games the local user has played.


public static int GetWonGames()

(Client) Gets the amount of games the local user has won.

Returns: (int) The amount of games the local user has won.


public static int GetXP()

(Client) Gets the amount of XP the local user has.

Returns: (int) XP amount.


public static int GetLevel()

(Client) Gets the XP level of the local user.

Returns: (int) The XP level.


public static void AddI18n(string translation)

(Client) Add a list of strings to the I18n table.

Arguments


public static string GetI18n(string key)

(Client) Gets a string from the I18n table.

Arguments

Returns: (string) The internationalized string.


public static string GetI18nParams(string key, LuaTable param)

(Client) Gets a string from the i18n table alongside parameters.

Arguments

Returns: (string) The internationalized string.


public static bool I18nExists(string key)

(Client) Checks whether a key exists in the i18n.

Arguments

Returns: (bool) Whether this key exists in the i18n.


public static string GetActiveLocale()

(Client) Gets the active locale.

Returns: (string) The active locale.


public static object LoadResource(string path, ResourceType type)

(Client) Load a resource from within Lua. Available types are:

ResourceType.Texture, ResourceType.Skybox, ResrouceType.Audio, ResourceType.MemoryAudio (if your sound is to be reused within multiple sources), ResourceType.Model, ResourceType.Text, ResourceType.Bytes.

Arguments

Returns: (many) The reference to the loaded resource.


public static bool IsLevelOfficial(string levelName)

(Client) Check whether a level is official or not.

Arguments

Returns: (bool) Whether this level is official.


public static bool CustomLevelExists(string levelName)

(Client) Check if a custom level exists in the VFS.

Arguments

Returns: (bool) Whether the custom level exists.


public static LuaTable GetAllCustomLevels()

(Client) Returns a table with all the installed custom maps in the VFS.

Returns: (LuaTable) A table with all the installed custom maps.


public static string GetRandomCustomLevel(string contains = "")

(Client) Returns a random custom level installed in the VFS.

Arguments

Returns: (string) Name of the level.


public static bool FileExists(string path)

(Client) Check if a file exists in the VFS.

Arguments

Returns: (bool) Whether the file exists.


public static bool DirectoryExists(string path)

(Client) Check if a directory exists in the VFS.

Arguments

Returns: (bool) Whether the directory exists.


public static LuaTable GetFilesInDirectory(string path)

(Client) Get path files inside a directory in the VFS.

Arguments

Returns: (LuaTable) A table with all file paths.


public static LuaTable GetFilesInDirectoryOfExtension(string path, string extension)

(Client) Get file paths of a specific extension inside a directory in the VFS. Pass empty extension to get folders.

Arguments

Returns: (LuaTable) A table with all file paths.


public static void WriteTextToFile(string path, string text)

(Client) Writes a string to a specified file.

Arguments


public static void WriteBytesToFile(string path, LuaByteArray stuff)

(Client) Writes binary data to a specified file.

Arguments


public static void CreateDirectory(string path)

Creates a directory at path.

Arguments


public static LuaByteArray WrapByteArray(byte[] bytes)

(Client) Wrap bytes from the internal lua representation into a byte array.

Arguments

Returns: (LuaByteArray) The byte array with the wrapped values.


public static bool IsNonExclusive()

(Client) Are we in a non-exclusive state?

Returns: (bool) Whether we're in a non-exclusive state.


public static void SetNonExclusive(bool isNonExclusive)

(Client) Sets whether we're in a non-exclusive state.

Arguments


public static LuaVector3 GetMousePosition()

(Client) Gets the mouse cursor position.

Returns: (Vector3) The mouse cursor position.


public static LuaVector3 GetScreenDimensions()

(Client) Gets the screen dimensions.

Returns: (Vector3) The screen dimensions.