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.Static Functions​
Returns | Name | Description | |
---|---|---|---|
Export | Makes any variable available in the global scope | ||
any | Require | Includes new .lua files | |
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 | ||
SetPersistentData | Sets a Persistent Value which will be saved to disk | ||
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 | |
string | GetTitle | Returns the package title | |
string | GetVersion | Returns the package version | |
string | GetCompatibilityVersion | Returns the package compatibility version | |
table | GetPersistentData | Gets the Persistent Value from the disk |
Export
​
Makes any variable available in the global scope
Package.Export(variable_name, value)
Type | Parameter | Default | Description |
---|---|---|---|
string | variable_name | Name of the variable to export | |
any | value | Value to be set in the global scope |
Require
​
Includes new .lua files
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/
— Returns any (Any return values from the included file).
local ret = Package.Require(script_file)
Type | Parameter | Default | Description |
---|---|---|---|
string | script_file | Path to the script file to require |
Subscribe
​
Subscribes to an Event
— Returns function (The function callback).
local ret = Package.Subscribe(event_name, callback)
Type | Parameter | Default | Description |
---|---|---|---|
string | event_name | Event to subscribe to | |
function | callback | Callback to run on the event occurring |
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?)
Type | Parameter | Default | Description |
---|---|---|---|
string | event_name | Event to unsubscribe to | |
function | callback? | nil | Optional callback to specifically unsubscribe to |
SetPersistentData
​
Sets a Persistent Value which will be saved to disk
Package.SetPersistentData(key, value)
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()
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()
GetCompatibilityVersion
​
Returns the package compatibility version
— Returns string (The package compatibility version).
local ret = Package.GetCompatibilityVersion()
GetPersistentData
​
Gets the Persistent Value from the disk
— Returns table (Persistent values from disk).
local ret = Package.GetPersistentData(key?)
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 all
the event triggers only after ALL packages are loaded.- In all other cases (
package load/reload
orPackage.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)