📦 Package
Class which represents the current Package
.. It's not possible to spawn new instances.🗿 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 | 取消订阅此特定类和此特定包中所有已订阅的事件,可选择传递函数以仅取消订阅该回调 |

Export
Makes any variable available in the global scope
Package.Export(variable_name, value)
| 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
— Returns string (The package compatibility version).
local ret = Package.GetCompatibilityVersion()

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

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

GetName
Returns the package name/path
— Returns string (The package name/path).
local ret = Package.GetName()

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

GetTitle
Returns the package title
— Returns string (The package title).
local ret = Package.GetTitle()

GetVersion
Returns the package version
— Returns string (The package version).
local ret = Package.GetVersion()

IsUnloading
Returns whether this package is currently unloading
— Returns boolean.
local ret = Package.IsUnloading()

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.
— Returns function (the compiled function to run the script, allowing you to pass a environment env table for the script with this format).
local ret = Package.LoadFile(file_path)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | file_path | Required parameter | Path to the script file to compile |
Package.LoadFile Examples
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.
— Returns any (any return values from the included file).
local ret = Package.Require(file_path, force_load?)
| 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 |
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)
| 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
— Returns function (The function callback).
local ret = Package.Subscribe(event_name, callback)
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | Event to subscribe to |
| function | callback | Required parameter | Callback to run on the event occurring |

Unsubscribe
取消订阅此特定类和此特定包中所有已订阅的事件,可选择传递函数以仅取消订阅该回调
Package.Unsubscribe(event_name, callback?)
| 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)