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
(table) The table of objects. An object can be either a string, or a table, with the first element being the name and the second being its offset. [objects]
(int) The offset of the beginning object. Defaults to 1. [offset]
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
(string) The name of the event. [eventName]
(many) The target of this event (can be nil). [evtEntity]
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
(string) The name of the event. [evtName]
(function) The callback that will be signaled when the event fires. [evtCallback]
(UnityObjectWrapper) The object this event will be fired on. Defaults to nil. [evtEntity]
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
(string) The name of the event. [evtName]
(any) The payload of this event. [evtCallback]
(UnityObjectWrapper) The object this event will be fired on. Defaults to nil. [evtEntity]
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
(string) The name of this RPC. It will be placed in the worldGlobals object. [name]
(SendTo) The direction this RPC goes.
(Delivery) The reliability of this RPC. Either "Delivery.Reliable" or "Delivery.Unreliable". [reliability]
(function) The callback that will be signaled after the RPC is received. [callback]
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
(string) The name of this variation. If this will be the default variation, set it to "default". [name]
(function) The function that will be fired at the beginning of the variation. [onBeginMicrogame]
(function) The function that will be executed on every frame of this variation's lifetime. Must take in one parameter (the time left). [onMicrogameTick]
(function) The function that will be fired at the end of the variation. [onPostMicrogame]
(int) The rarity of the variation. The higher this value is, the more common it is. Defaults to 8. [rarity]
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
(string) The name of this variation. If this will be the default variation, set it to "default". [name]
(function) The function that will be fired before the microgame starts, during the intermission. [onPrepareMicrogame]
(function) The function that will be fired at the beginning of the variation. [onBeginMicrogame]
(function) The function that will be executed on every frame of this variation's lifetime. Must take in one parameter (the time left). [onMicrogameTick]
(function) The function that will be fired at the end of the variation. [onPostMicrogame]
(int) The rarity of the variation. The higher this value is, the more common it is. Defaults to 8. [rarity]
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
(string) The name of this microgame, this will be used for both I18n and synchronization. [name]
(table) The table that holds the music for this microgame. Has to have 6 "AudioResource" elements. [musicArray]
(table) The table that holds the variations for this microgame (returned from CreateMicrogameVariation). Every microgame has to have at least 1 variation. [variationsArray]
(table) Extra data about this microgame.
Its elements are: "Difficulty", "Rarity", "MinPlayers", "Type". Any of these elements can be left empty, as the function will auto-fill them.
"Difficulty" is the overall difficulty of this microgame. Its values are: "Difficulty.VeryEasy", "Difficulty.Easy", "Difficulty.Medium", "Difficulty.Hard". Defaults to Easy.
"Rarity" is the rarity of the microgame. Same as with CreateMicrogameVariation.
"MinPlayers" is the minimum amount of players required for this microgame. Defaults to 1.
"Type" is the internal type of this microgame. This isn't used much, other than for a special round. Values are "MicrogameType.WinAtEnd", "MicrogameType.WinBeforeEnd", "MicrogameType.Versus", "MicrogameType.Coop". Defaults to WinBeforeEnd.
"PlayEffect" toggles whether we play the win effect right as the player is declared the winner by the coordinator. Defaults to false.
This table can be left nil. [params]
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
(string) The language code. [language]
(string) The I18n data. [data]
function RequestAvatar(player, callback)
Requests a player's avatar and returns it in a callback.
Arguments
(PlayerController) The player you want to get an avatar from. [player]
(function) The function to execute when avatar is received. For example, RequestAvatar(player, function(pay) pay:GetAvatar() end)
[callback]
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
(string) The key. [key]
(string) The value. [value]
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
(Vector3) Origin of the raycast [origin]
(Vector3) Direction of the raycast [direction]
(float) Maximum length of the raycast [length]
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
(Vector3) Origin of the raycast [origin]
(Vector3) Direction of the raycast [direction]
(float) Maximum length of the raycast [length]
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
(Vector3) Origin of the spherecast [origin]
(Vector3) Direction of the spherecast [direction]
(float) Radius of the sphere. [radius]
(float) Maximum length of the spherecast [length]
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
(Vector3) Origin of the spherecast [origin]
(Vector3) Direction of the spherecast [direction]
(float) Radius of the sphere. [radius]
(float) Maximum length of the spherecast [length]
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
(Vector3) Origin point. [origin]
(float) Radius of sphere. [radius]
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
(Vector3) Origin point. [origin]
(float) Radius of sphere. [radius]
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
(Vector3) Origin point. [startPoint]
(Vector3) End point. [endPoint]
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
(string) The key for the string. [key]
(table) The table of objects. It should look like this: "{ {"key1", "value1"}, {"key2", "value2"} }" [param]
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
(string) The path within the Virtual File System to the file. [path]
(ResourceType) The type of the resource. [type]
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
(string) The path within the Virtual File System to the directory. [path]
(string) File extension to filter for. [extension]
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
(string) The path to write to within the VFS. [path]
(string) The string to write. [text]
public static void WriteBytesToFile(string path, LuaByteArray stuff)
(Client) Writes binary data to a specified file.
Arguments
(string) The path to write to within the VFS. [path]
(LuaByteArray) The binary data to write. [text]
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.