๐ฆ Package
Class which represents the current Package
๐ฟStatic Class
This is a Static Class. Access it's methods directly with
.. It's not possible to spawn new instances.๐งโ๐ปAPI Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!
๐ฟย Static Functionsโ
| Returns | Name | Description | |
|---|---|---|---|
Export | Makes any variable available in the global scope | ||
FlushPersistentData | Flushes the Persistent Data pending changes to disk immediately | ||
| string | GetCompatibilityVersion | Returns the package compatibility version | |
| table of string | GetDirectories | Gets a list of all directories in this package | |
| table of string | GetFiles | Gets a list of all files in this package | |
| string | GetName | Returns the package name/path | |
| table | GetPersistentData | Gets the Persistent Value from the disk | |
| string | GetTitle | Returns the package title | |
| string | GetVersion | Returns the package version | |
| boolean | IsUnloading | Returns whether this package is currently unloading | |
| function | LoadFile | Compiles a .lua file and returns a function to run it | |
| any | Require | Loads a .lua file | |
SetPersistentData | Sets a Persistent Value which will be saved to disk | ||
| function | Subscribe | Subscribes to an Event | |
Unsubscribe | Unsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback |

Export
โ
Makes any variable available in the global scope
Package.Export(variable_name, value)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | variable_name | Required parameter | Name of the variable to export |
| any | value | Required parameter | Value to be set in the global scope |

FlushPersistentData
โ
Flushes the Persistent Data pending changes to disk immediately
Package.FlushPersistentData()

GetCompatibilityVersion
โ
Returns the package compatibility version
local ret = Package.GetCompatibilityVersion()
Returns
| Type | Description |
|---|---|
| string | The package compatibility version |

GetDirectories
โ
Gets a list of all files in this package, optionally with filters
local ret = Package.GetDirectories(path_filter?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | path_filter? | | Path filter |

GetFiles
โ
Gets a list of all files in this package, optionally with filters
local ret = Package.GetFiles(path_filter?, extension_filter?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string or table | path_filter? | | Path filter |
| string | extension_filter? | | Example: .lua |

GetName
โ
Returns the package name/path
local ret = Package.GetName()
Returns
| Type | Description |
|---|---|
| string | The package name/path |

GetPersistentData
โ
Gets the Persistent Value from the disk
local ret = Package.GetPersistentData(key?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | key? | | The key to get the data |
Returns
| Type | Description |
|---|---|
| table | Persistent values from disk |
See also SetPersistentData.

GetTitle
โ
Returns the package title
local ret = Package.GetTitle()
Returns
| Type | Description |
|---|---|
| string | The package title |

GetVersion
โ
Returns the package version
local ret = Package.GetVersion()
Returns
| Type | Description |
|---|---|
| string | The package version |

IsUnloading
โ
Returns whether this package is currently unloading
local ret = Package.IsUnloading()
Returns
| Type | Description |
|---|---|
| boolean | No description provided |

LoadFile
โ
Compiles a .lua file and returns a function to run it. To be used for loading files in a sandboxed environment.
Supports the same searchers as Package.Require.
local ret = Package.LoadFile(file_path)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | file_path | Required parameter | Path to the script file to compile |
Returns
| Type | Description |
|---|---|
| function | the compiled function to run the script, allowing you to pass a environment env table for the script with this format |
Package.LoadFile Examples
Loading a .lua file sandboxed
local func = Package.LoadFile("MyScript.lua")
-- Only allows this file to access Console
local my_env = { Console = Console }
local content = func(my_env)
-- Access all global variables set by the script in my_env
my_env.GlobalVariableFromFile...
See also Require.

Require
โ
Loads a .lua file. Note that this method caches the result, so further calls return the cached value.
We currently support 5 searchers, which are looked in the following order:
- Relative to
current-file-path/- Relative to
current-package/Client/orcurrent-package/Server/(depending on your side)- Relative to
current-package/Shared/- Relative to
current-package/- Relative to
Packages/Note: Clients will only download and have access to
Client/andShared/folders.
local ret = Package.Require(file_path, force_load?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | file_path | Required parameter | Path to the script file to load |
| boolean | force_load? | false | Whether to force loading this file even if it was already loaded |
Returns
| Type | Description |
|---|---|
| any | any return values from the included file |
See also LoadFile.

SetPersistentData
โ
Sets a Persistent Value which will be saved to disk. Note the actual flush to disk is deferred and may not occur immediately
Package.SetPersistentData(key, value)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | key | Required parameter | Key to index data into. It can be separated by '.' to set a child element. |
| any | value | Required parameter | Value to set at the key |
See also GetPersistentData.

Subscribe
โ
Subscribes to an Event
local ret = Package.Subscribe(event_name, callback)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | Event to subscribe to |
| function | callback | Required parameter | Callback to run on the event occurring |
Returns
| Type | Description |
|---|---|
| function | The function callback |

Unsubscribe
โ
Unsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback
Package.Unsubscribe(event_name, callback?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | Event to unsubscribe to |
| function | callback? | nil | Optional callback to specifically unsubscribe to |
๐ย Eventsโ

Loadโ
Called when this package is loaded
This event is triggered differently depending on the situation:
- When the server starts or you run
package reload allthe event triggers only after ALL packages are loaded.- In all other cases (
package load/reloadorPackage.Load/Reload) the event is triggered immediately after the package is loaded/reloaded.
Package.Subscribe("Load", function()
-- Load was called
end)

Unloadโ
Called when this package is unloaded
Package.Subscribe("Unload", function()
-- Unload was called
end)