Skip to content

GlobalScript

Global scripts are .lua files starting with g_ that can be placed anywhere in your mod's folder.

They're used for most code modifications of the game.

Functions

PreventTimePassing

 function self.PreventTimePassing()

GlobalScript.PreventTimePassing

Prevents time from progressing in the game


AllowTimePassing

 function self.AllowTimePassing()

GlobalScript.AllowTimePassing

Allows time from progressing in the game


CallNextFrame

 function self.CallNextFrame((function)Function , (parameters)Other Parameters)
Parameter Type 📝 Description
Function function Function to be called
Other Parameters parameters This method can be called with aditional parameters to be sent to the function to be called.

GlobalScript.CallNextFrame

Calls a function after one frame has passed.

Example

self.CallNextFrame(TestFunction,"Test")
This example will call the function TestFunction with the parameter 'Test' in one frame.


RegisterGlobalFunction

 function self.RegisterGlobalFunction((string)ID , (Function)Function)
Parameter Type 📝 Description
ID string Id to register. This id will be used by other scripts to find and call this function.
Function Function Function to register.

GlobalScript.RegisterGlobalFunction

Registers a function in this script as a global function that can be used by other scripts.

Example

self.RegisterGlobalFunction("Test")
This example registers the function 'DoTest' as a global function with the id 'Test'.


Include

 function self.Include((filename without the extension)File)
Parameter Type 📝 Description
File filename without the extension Filename without the extension Make sure this file is within the 'libraries' folder of the mod.

GlobalScript.Include

Includes another lua file in this global script.

Example

self.Include("file")
This example includes a file called file.


CallFunctionOnOthers

 function self.CallFunctionOnOthers((string)Function Name , (parameters)Other Parameters)
Parameter Type 📝 Description
Function Name string Function name as a string
Other Parameters parameters Other parameters to call on this function. Can only take Numbers, Booleans, Strings, Simple Tables. When in doubt if it's a type that is acceptable send it as a json.

GlobalScript.CallFunctionOnOthers

Call a function on other players in the room. Make sure the script that will receive the function has called self.ListenForNetworkCalls() before.

Example

self.CallFunctionOnOthers("Test","This is a test")
This example calls the function 'Test' on other players in the room with the string parameter 'This is a test'.


CallFunctionOnEveryone

 function self.CallFunctionOnEveryone((string)Function Name , (parameters)Other Parameters)
Parameter Type 📝 Description
Function Name string Function name as a string
Other Parameters parameters Other parameters to call on this function. Can only take Numbers, Booleans, Strings, Simple Tables. When in doubt if it's a type that is acceptable send it as a json.

GlobalScript.CallFunctionOnEveryone

Call a function on all players in the room including your own. Make sure the script that will receive the function has called self.ListenForNetworkCalls() before.

Example

self.CallFunctionOnEveryone("Test","This is a test")
This example calls the function 'Test' on all players in the room including your own with the string parameter 'This is a test'.


CallFunctionOnHost

 function self.CallFunctionOnHost((string)Function Name , (parameters)Other Parameters)
Parameter Type 📝 Description
Function Name string Function name as a string
Other Parameters parameters Other parameters to call on this function. Can only take Numbers, Booleans, Strings, Simple Tables. When in doubt if it's a type that is acceptable send it as a json.

GlobalScript.CallFunctionOnHost

Call a function on the host of the room. Make sure the script that will receive the function has called self.ListenForNetworkCalls() before.

Example

self.CallFunctionOnHost("Test","This is a test")
This example calls the function 'Test' on the host of the room with the string parameter 'This is a test'.


ListenForNetworkCalls

 function self.ListenForNetworkCalls()

GlobalScript.ListenForNetworkCalls

Start listening for function calls from other players in the room.

Example
self.ListenForNetworkCalls()

StopListeningForNetworkCalls

 function self.StopListeningForNetworkCalls()

GlobalScript.StopListeningForNetworkCalls

Stop listening for function calls from other players in the room.

Example
self.StopListeningForNetworkCalls()

RegisterListener

 function self.RegisterListener((int)MessageToListen , (function)Function to Call)
Parameter Type 📝 Description
MessageToListen int The id of one of the messages available on the Messager. Example: Messager.Update
Function to Call function The function that should be called once this message is sent.

GlobalScript.RegisterListener

Registers for Messager messages.

Example

self.RegisterListener(Messager.Update,Test)
This example will call the function Test every time Update message is sent by the messager.


UnregisterListener

 function self.UnregisterListener((int)MessageToStopListening)
Parameter Type 📝 Description
MessageToStopListening int The id of one of the messages available on the Messager. Example: Messager.Update

GlobalScript.UnregisterListener

Unregister from Messager messages.

Example

self.UnregisterListener(Messager.Update)
This example will stop calling the function Test every time Update message is sent by the messager.


ConsumeUsable

 function self.ConsumeUsable()

GlobalScript.ConsumeUsable

If the player currently has a UsableLua selected it will consume it.

Example
self.ConsumeUsable()

Comments