Avorion Script API Documentation

Sector Script Predefined Functions

Tip: Scroll down for an example script!

function updateServer(timeStep)

Update tick that is only executed on the server. See the documentation for getUpdateInterval() for details on the frequency of these calls.

Server Function: This function is only called on the server.

Parameters

timeStep The amount of time that passed since the last update tick

function initialize(...)

This function is always the very first function that is called in a script, and only once during the lifetime of the script. The function is always called on the server first, before client instances are available, so invoking client functions will never work. This function is both called when a script gets newly attached to an object, and when the object is loaded from the database during a load from disk operation. During a load from disk operation, no parameters are passed to the function, and a global variable '_restoring' is set to true.

Parameters

... Parameters that are passed through from the adding of the script. nil if the script was loaded from the database while loading a sector or player or similar.

function update(timeStep)

Called every tick, both on client and server. See the documentation for getUpdateInterval() for details on the frequency of these calls.

Parameters

timeStep The amount of time passed since the last update tick

function getUpdateInterval()

Defines the update tick interval of the script. This interval can not be less than the update tick interval of the server or client, depending on where the script is running. The update(), updateParallelRead(), updateParallelSelf(), updateClient() and updateServer() functions will only be called after at least this much time has passed. The minimum update interval for the client varies with the framerate of the client. The minimum update interval for the server is 50 ms. This function is called after initialize() or after the update functions were called. If this function is not defined, the update functions will be called every tick.

Expected return values

The desired update tick interval in seconds

function onRemove()

Called when the script is about to be removed from the object, before the removal.

function onDelete()

Called when the script is about to be deleted from the object, before the deletion. This is the last call that will be done to an object script. This function is also called when the object it is attached to is deleted.

function secure()

Called to secure values from the script. This function is called when the object is unloaded from the server. It's called at other times as well to refresh data, or when objects are copied or during regular saves. The table returned by this function will be passed to the restore() function when the object is loaded and read from disk. All values that are in the table must be numbers, strings or other tables. Values that aren't of the above types will be converted to nil and an error message will be printed.

Expected return values

A table containing values that should be saved

function restore(values)

Called to restore previously secured values for the script. This is called after initialize(). Receives the values that were gathered from the last called to the secure() function. This function is called when the object is read from disk and restored, after initialize() was called.

Parameters

values The table previously returned by the secure() function

function updateClient(timeStep)

Update tick that is only executed on the client. See the documentation for getUpdateInterval() for details on the frequency of these calls.

Client Function: This function is only called on the client.

Parameters

timeStep The amount of time that passed since the last update tick


Sector Example Script

-- Update tick that is only executed on the server. See the documentation for getUpdateInterval()
-- for details on the frequency of these calls.
-- Server Function: This function is only called on the server.
function updateServer(timeStep)

end

-- This function is always the very first function that is called in a script, and only once during
-- the lifetime of the script. The function is always called on the server first, before client
-- instances are available, so invoking client functions will never work. This function is both
-- called when a script gets newly attached to an object, and when the object is loaded from the
-- database during a load from disk operation. During a load from disk operation, no parameters
-- are passed to the function, and a global variable '_restoring' is set to true.
function initialize(...)

end

-- Called every tick, both on client and server. See the documentation for getUpdateInterval()
-- for details on the frequency of these calls.
function update(timeStep)

end

-- Defines the update tick interval of the script. This interval can not be less than the update
-- tick interval of the server or client, depending on where the script is running. The update(),
-- updateParallelRead(), updateParallelSelf(), updateClient() and updateServer() functions will
-- only be called after at least this much time has passed. The minimum update interval for the
-- client varies with the framerate of the client. The minimum update interval for the server
-- is 50 ms. This function is called after initialize() or after the update functions were called.
-- If this function is not defined, the update functions will be called every tick.
function getUpdateInterval()

end

-- Called when the script is about to be removed from the object, before the removal.
function onRemove()

end

-- Called when the script is about to be deleted from the object, before the deletion. This is
-- the last call that will be done to an object script. This function is also called when the
-- object it is attached to is deleted.
function onDelete()

end

-- Called to secure values from the script. This function is called when the object is unloaded
-- from the server. It's called at other times as well to refresh data, or when objects are copied
-- or during regular saves. The table returned by this function will be passed to the restore()
-- function when the object is loaded and read from disk. All values that are in the table must
-- be numbers, strings or other tables. Values that aren't of the above types will be converted
-- to nil and an error message will be printed.
function secure()

end

-- Called to restore previously secured values for the script. This is called after initialize().
-- Receives the values that were gathered from the last called to the secure() function. This
-- function is called when the object is read from disk and restored, after initialize() was called.
function restore(values)

end

-- Update tick that is only executed on the client. See the documentation for getUpdateInterval()
-- for details on the frequency of these calls.
-- Client Function: This function is only called on the client.
function updateClient(timeStep)

end
Overview
Home Functions Search
Search:

This is the official documentation for the scripting API of Avorion. This documentation is automatically generated and not necessarily complete. Depending on the context in which functions exist, some documentation such as descriptions, return values or variable names or types may be missing.

Work in Progress. Documentation of Avorion Version: 2.5.7 c8e4beec84f7