Skip to main content
Version: bleeding-edge ๐Ÿฉธ

๐Ÿ“ฆ 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.
๐Ÿ’‚Authority
This static class can be accessed on both ๐ŸŸง Client and ๐ŸŸฆ Server side.
๐Ÿง‘โ€๐Ÿ’ป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โ€‹

ReturnsNameDescription
ExportMakes any variable available in the global scope
FlushPersistentDataFlushes the Persistent Data pending changes to disk immediately
stringGetCompatibilityVersionReturns the package compatibility version
table of stringGetDirectoriesGets a list of all directories in this package
table of stringGetFilesGets a list of all files in this package
stringGetNameReturns the package name/path
tableGetPersistentDataGets the Persistent Value from the disk
stringGetTitleReturns the package title
stringGetVersionReturns the package version
booleanIsUnloadingReturns whether this package is currently unloading
functionLoadFileCompiles a .lua file and returns a function to run it
ReloadClientFileReloads a file from Client/ or Shared/ folder and sends the updated version to clients, triggering the FileReload event on them
anyRequireLoads a .lua file
SetPersistentDataSets a Persistent Value which will be saved to disk
functionSubscribeSubscribes to an Event
UnsubscribeUnsubscribes 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

TypeParameterDefaultDescription
stringvariable_name Required parameter Name of the variable to export
anyvalue 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

TypeDescription
stringThe package compatibility version

GetDirectoriesโ€‹

Gets a list of all files in this package, optionally with filters
local ret = Package.GetDirectories(path_filter?)

Parameters

TypeParameterDefaultDescription
stringpath_filter?Path filter

Returns

TypeDescription
table of stringList of directories

GetFilesโ€‹

Gets a list of all files in this package, optionally with filters
local ret = Package.GetFiles(path_filter?, extension_filter?)

Parameters

TypeParameterDefaultDescription
string or tablepath_filter?Path filter
stringextension_filter?Example: .lua

Returns

TypeDescription
table of stringList of files

GetNameโ€‹

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

Returns

TypeDescription
stringThe package name/path

GetPersistentDataโ€‹

Gets the Persistent Value from the disk
local ret = Package.GetPersistentData(key?)

Parameters

TypeParameterDefaultDescription
stringkey?The key to get the data

Returns

TypeDescription
tablePersistent values from disk

See also SetPersistentData.


GetTitleโ€‹

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

Returns

TypeDescription
stringThe package title

GetVersionโ€‹

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

Returns

TypeDescription
stringThe package version

IsUnloadingโ€‹

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

Returns

TypeDescription
booleanNo 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

TypeParameterDefaultDescription
stringfile_path Required parameter Path to the script file to compile

Returns

TypeDescription
functionthe 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.


ReloadClientFileโ€‹

Reloads a file from Client/ or Shared/ folder and sends the updated version to clients, triggering the FileReload event on them

The reloaded file will be re-cached and downloaded normally by new connecting clients

Note that this method does use the main network lane, so it is not recommended to be used frequently or with large files in production environments as it may cause network congestion and lag spikes. It is mostly intended for development purposes to allow faster iteration on client files without needing to reload the whole package
Package.ReloadClientFile(file_path)

Parameters

TypeParameterDefaultDescription
stringfile_path Required parameter The file path relative to the package root

See also FileReload.


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:
  1. Relative to current-file-path/
  2. Relative to current-package/Client/ or current-package/Server/ (depending on your side)
  3. Relative to current-package/Shared/
  4. Relative to current-package/
  5. Relative to Packages/

Note: Clients will only download and have access to Client/ and Shared/ folders.

local ret = Package.Require(file_path, force_load?)

Parameters

TypeParameterDefaultDescription
stringfile_path Required parameter Path to the script file to load
booleanforce_load?falseWhether to force loading this file even if it was already loaded

Returns

TypeDescription
anyany 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

TypeParameterDefaultDescription
stringkey Required parameter Key to index data into. It can be separated by '.' to set a child element.
anyvalue Required parameter Value to set at the key

See also GetPersistentData.


Subscribeโ€‹

Subscribes to an Event
local ret = Package.Subscribe(event_name, callback)

Parameters

TypeParameterDefaultDescription
stringevent_name Required parameter Event to subscribe to
functioncallback Required parameter Callback to run on the event occurring

Returns

TypeDescription
functionThe 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

TypeParameterDefaultDescription
stringevent_name Required parameter Event to unsubscribe to
functioncallback?nilOptional callback to specifically unsubscribe to

๐Ÿš€ย Eventsโ€‹

NameDescription
FileReloadCalled when a file is directly reloaded from the server using Package.ReloadClientFile()
LoadCalled when this package is loaded
UnloadCalled when this package is unloaded

FileReloadโ€‹

Called when a file is directly reloaded from the server using Package.ReloadClientFile()

You can use the path to reload the file in runtime with Package.Require(path, true)
Package.Subscribe("FileReload", function(file_path)
-- FileReload was called
end)

Arguments

TypeArgumentDescription
stringfile_pathThe file path

See also ReloadClientFile.


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 or Package.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)