Skip to content

Class: object_binder<T>

Script-side binder attached to a client game_object.

Source

src/xrGame/script_binder_object_script.cpp, object_binder binding.

Source

src/xrGame/script_binder.cpp, CScriptBinder.

Custom Constructor

object_binder

Remarks

A config section can name a script_binding function. During reload, the engine calls that function with the object's game_object; the script normally creates an object_binder subclass for it. Binder hooks are client-object hooks. Server ALife objects use cse_alife_dynamic_object lifecycle methods instead.

Base hook implementations are empty, except net_spawn returns true and net_save_relevant returns false. If a hook throws, the engine clears the binder.

Extends

Type Parameters

Type ParameterDefault type
Tgame_object

Constructors

Constructor

ts
new object_binder<T>(object: T): object_binder<T>;

Create a binder for a script game object.

Parameters

ParameterTypeDescription
objectTScript game object controlled by this binder.

Returns

object_binder<T>

Overrides

EngineBinding.constructor

Methods

load()

ts
load(reader: reader): void;

Load binder state.

Parameters

ParameterTypeDescription
readerreaderSource save reader.

Returns

void

Remarks

Read data written by save. The engine does not validate custom binder packet layouts.


net_destroy()

ts
net_destroy(): void;

Handle this client object destruction.

Returns

void

Remarks

Called when this client object goes offline or is destroyed. This is the binder's own cleanup hook. net_Relcase is for another object being released.


net_export()

ts
net_export(net_packet: net_packet): void;

Export binder network state.

Parameters

ParameterTypeDescription
net_packetnet_packetDestination network packet.

Returns

void

Remarks

Pair this with net_import when the binder participates in network state synchronization.


net_import()

ts
net_import(net_packet: net_packet): void;

Import binder network state.

Parameters

ParameterTypeDescription
net_packetnet_packetSource network packet.

Returns

void

Remarks

Pair this with net_export when the binder participates in network state synchronization.


net_Relcase()

ts
net_Relcase(object: T): void;

Release references to a game object that is about to be destroyed.

Parameters

ParameterTypeDescription
objectTObject being released.

Returns

void

Source

src/xrEngine/xr_object_list.cpp, CObjectList::SingleUpdate.

Source

src/xrGame/GameObject.cpp, CGameObject::net_Relcase.

Source

src/xrGame/script_binder.cpp, CScriptBinder::net_Relcase.

Remarks

The engine broadcasts this to every active and sleeping client object for every object in the destroy queue. Use it only to drop references to object; the callback is not limited to binders that reference it.

Keep overrides small, tolerate unrelated objects, and do not store or use object after this callback returns. The broadcast cost is roughly (active + sleeping client objects) * destroyed objects.


net_save_relevant()

ts
net_save_relevant(): boolean;

Decide whether binder state should be saved over the network.

Returns

boolean

Whether the state is relevant for network save.

Remarks

The base implementation returns false.


net_spawn()

ts
net_spawn(object: cse_alife_object): boolean;

Handle network spawn.

Parameters

ParameterTypeDescription
objectcse_alife_objectServer object used for spawn data.

Returns

boolean

Whether spawn succeeded.

Source

src/xrGame/script_binder.cpp, CScriptBinder::net_Spawn.

Remarks

Client-side online spawn hook. It can run again for the same logical ALife object when the engine recreates its online client object. Return false to reject the client spawn. The base implementation returns true.


reinit()

ts
reinit(): void;

Reinitialize binder runtime state.

Returns

void

Remarks

Called when the owning client object is reinitialized. Keep persistent state in save and load, not here.


reload()

ts
reload(section: string): void;

Reload binder configuration.

Parameters

ParameterTypeDescription
sectionstringObject config section.

Returns

void

Remarks

Called after the engine creates the script binder from the section's script_binding callback.


save()

ts
save(packet: net_packet): void;

Save binder state.

Parameters

ParameterTypeDescription
packetnet_packetDestination save packet.

Returns

void

Remarks

Write only data that load will read back in the same order.


update()

ts
update(delta: number): void;

Update binder logic.

Parameters

ParameterTypeDescription
deltanumberTime since last update in milliseconds.

Returns

void

Remarks

Called from the owning client object's scheduled update while the object is online.

Properties

__name

ts
readonly __name: string;

LuaBind instance constructor name.

Inherited from

EngineBinding.__name


object

ts
readonly object: T;

Client game_object controlled by this binder.

Remarks

The engine passes this object to the constructor and stores the binder on the native client object. Treat the reference as engine-owned.


__name

ts
readonly static __name: string;

LuaBind class constructor name.

Inherited from

EngineBinding.__name