Class EntityScript

Class Documentation

class EntityScript

Manages the script attached to an Entity.

Provides functions for setting the script source, subscribing to property changes and messages and other script management.

Public Functions

~EntityScript()

Destroy the instance of EntityScript.

void SetScriptSource(const csp::common::String &ScriptSource)

Sets the source code for the script.

Parameters

ScriptSourcecsp::common::String : The source as a string.

bool Invoke()

Runs the script.

Returns

True if the script runs successfully or false if there are errors.

void RunScript(const csp::common::String &ScriptSource)

Run a script with the given source rather than the stored source.

Will be run locally or remotely depending on leader election.

Parameters

ScriptSourcecsp::common::String : The source to use.

bool HasError()

Checks if there was an error with the last script invocation.

Returns

True if there was an error, false otherwise.

csp::common::String GetErrorText()

Gets the text of the last error if it is known or otherwise returns a default unknown error string.

Returns

Text of the last error.

csp::common::String GetScriptSource()

Gets the stored script source code.

Returns

The source as a string.

void SetScriptSpaceComponent(ScriptSpaceComponent *InEnityScriptComponent)

Sets the related component for this script.

Parameters

InEnityScriptComponentScriptSpaceComponent : The component related to this script.

void OnPropertyChanged(int32_t ComponentId, int32_t PropertyKey)

Called when a component property changes so that a message can be passed to the script if a subscription has been setup.

Parameters
  • ComponentId – int32_t : ID of the component that changed.

  • PropertyKey – int32_t : Key of the property that changed.

void SubscribeToPropertyChange(int32_t ComponentId, int32_t PropertyKey, csp::common::String Message)

Sets up a subscription where the given message is posted to the script when a change is made to the specified component property.

Parameters
  • ComponentId – int32_t : The ID of the component that the property belongs to.

  • PropertyKey – int32_t : The key of the component property to subscribe to changes of.

  • Messagecsp::common::String : The message that will be posted to the script when a change occurs to the property.

void SubscribeToMessage(const csp::common::String Message, const csp::common::String OnMessageCallback)

Sets up a subscription where the given callback in the script will be run when given message is posted to the script.

Parameters
void PostMessageToScript(const csp::common::String Message, const csp::common::String MessageParamsJson = "")

Runs the callback associated with the given message, if a subscription has been setup, and passes the given params.

Parameters
void OnSourceChanged(const csp::common::String &InScriptSource)

Resets binding, context and subscriptions when the source is changed for the script.

Parameters

InScriptSourcecsp::common::String : The new source for the script.

void RegisterSourceAsModule()

Registers the script source for the related entity in the script system.

void Bind()

Binds the related entity in the script system.

void SetOwnerId(uint64_t ClientId)

Sets the owner of the script.

Parameters

ClientId – uint64_t : The ID of the client to be set as owner.

uint64_t GetOwnerId() const

Get the owner of the script.

Returns

The client ID of the owner.

void Shutdown()

Removes the script source and context from the script system.