AgentScript

AgentScript Class

Extend AgentScript to create a script to be attached directly to an agent. For future use: Sansar does not currently support adding scripts to agents.

Syntax

[Sansar.Script.Interface]
public abstract class AgentScript : Sansar.Script.ScriptBase

Remarks

Override Sansar.Script.ScriptBase.Init() for script initialization, primarily event subscriptions.

Use AgentScript.ObjectPrivate to access the ObjectPrivate the object that represents the Agent.

Use AgentScript.ScenePublic to access the a limited API for the Scene the agent is in.

Use AgentScript.AgentPrivate to access the Agent the object is attached to.

C# Example
/* This content is licensed under the terms of the Creative Commons Attribution 4.0 International License.
 * When using this content, you must:
 * �    Acknowledge that the content is from the Sansar Knowledge Base.
 * �    Include our copyright notice: "� 2017 Linden Research, Inc."
 * �    Indicate that the content is licensed under the Creative Commons Attribution-Share Alike 4.0 International License.
 * �    Include the URL for, or link to, the license summary at https://creativecommons.org/licenses/by-sa/4.0/deed.hi (and, if possible, to the complete license terms at https://creativecommons.org/licenses/by-sa/4.0/legalcode.
 * For example:
 * "This work uses content from the Sansar Knowledge Base. � 2017 Linden Research, Inc. Licensed under the Creative Commons Attribution 4.0 International License (license summary available at https://creativecommons.org/licenses/by/4.0/ and complete license terms available at https://creativecommons.org/licenses/by/4.0/legalcode)."
 */
using Sansar.Simulation;
using System.ComponentModel;

// To get full access to the Agent API a script must extend from AgentScript
public class AgentScriptExample : AgentScript
{
    // Public fields of supported types are reflected in the editor. 
    [DefaultValue("The script attached to this agent has been initialized.")]
    public string WelcomeMessage = null;

    public AgentScriptExample()
    {
        // WelcomeMessage will be null in the constructor, as will Agent.
        // Any value assigned to WelcomeMessage will be overwritten before Init is called.
    }

    // Init will be called by the script loader after the constructor and after any public fields have been initialized.
    public override void Init()
    {
        // Agent is now valid and can be used to display a message on the client.
        // Even though there is no code shown which assigns to WelcomeMessage, it will have a value assigned by the editor.
        AgentPrivate.Client.UI.ModalDialog.Show(WelcomeMessage, "Cancel", "Okay", OnDialogResponse);
    }

    // This method will be called when the client presses a button on the dialog.
    void OnDialogResponse(bool Success, string Message)
    {
        AgentPrivate.SendChat("The client pressed " + Message);
    }
}

Requirements

Namespace: Sansar.Simulation
Assembly: Sansar.Simulation (in Sansar.Simulation.dll)
Assembly Versions: 1.1.0.0

Members

See Also: Inherited members from Sansar.Script.ScriptBase.

Protected Constructors

  This constructor is called before any properties have been set. Override Sansar.Script.ScriptBase.Init() to initialize the script after properties have been set.

Public Properties

  AgentPrivate AgentPrivate . The Agent API for the agent this script is attached to.
  Log Sansar.Script.Log . Gets the script console. (Inherited from Sansar.Script.ScriptBase.)
  Memory Sansar.Script.Memory . Memory information for the pool this script is in. (Inherited from Sansar.Script.ScriptBase.)
  ObjectPrivate ObjectPrivate . The ObjectPrivate this script is attached to if it is attached to an object.
  ScenePublic ScenePublic . Basic scene information for the current scene.
  Script Sansar.Script.ScriptHandle . Script handle to this script. (Inherited from Sansar.Script.ScriptBase.)

Public Methods

abstract
Init ()
Init() is called after all interfaces have been initialized. (Inherited from Sansar.Script.ScriptBase.)

Protected Methods

  StartCoroutine (Action)
Starts a coroutine on the current script. (Inherited from Sansar.Script.ScriptBase.)
  StartCoroutine<T> (Action<T>T)
Starts a coroutine on the current script. (Inherited from Sansar.Script.ScriptBase.)
  StartCoroutine<T,T1> (Action<T, T1>TT1)
Starts a coroutine on the current script. (Inherited from Sansar.Script.ScriptBase.)
  StartCoroutine<T,T1,T2> (Action<T, T1, T2>TT1T2)
Starts a coroutine on the current script. (Inherited from Sansar.Script.ScriptBase.)
  StartCoroutine<T,T1,T2,T3> (Action<T, T1, T2, T3>TT1T2T3)
Starts a coroutine on the current script. (Inherited from Sansar.Script.ScriptBase.)
  Terminate (string)
Terminates this script immediately. (Inherited from Sansar.Script.ScriptBase.)
  Wait (TimeSpan)
Delays execution of the current coroutine for the specified time. (Inherited from Sansar.Script.ScriptBase.)
  WaitFor (Action<Action<Sansar.Script.EventData>,System.Boolean>) : Sansar.Script.EventData
Use in a coroutine to pause the script until an event happens. (Inherited from Sansar.Script.ScriptBase.)
  WaitFor<ARG1> (Action<ARG1, Action<Sansar.Script.EventData>,System.Boolean>ARG1) : Sansar.Script.EventData
Use in a coroutine to pause the script until an event happens. (Inherited from Sansar.Script.ScriptBase.)
  WaitFor<T1> (Func<T1, Action<Sansar.Script.OperationCompleteEvent>,System.UInt64>T1) : Sansar.Script.OperationCompleteEvent
Use in a coroutine to pause the script until an event happens. (Inherited from Sansar.Script.ScriptBase.)
  WaitFor<ARG1,ARG2> (Action<ARG1, ARG2, Action<Sansar.Script.EventData>,System.Boolean>ARG1ARG2) : Sansar.Script.EventData
Use in a coroutine to pause the script until an event happens. (Inherited from Sansar.Script.ScriptBase.)
  WaitFor<T1,T2> (Func<T1, T2, Action<Sansar.Script.OperationCompleteEvent>,System.UInt64>T1T2) : Sansar.Script.OperationCompleteEvent
Use in a coroutine to pause the script until an event happens. (Inherited from Sansar.Script.ScriptBase.)
  WaitFor<ARG1,ARG2,ARG3> (Action<ARG1, ARG2, ARG3, Action<Sansar.Script.EventData>,System.Boolean>ARG1ARG2ARG3) : Sansar.Script.EventData
Use in a coroutine to pause the script until an event happens. (Inherited from Sansar.Script.ScriptBase.)
  WaitFor<T1,T2,T3> (Func<T1, T2, T3, Action<Sansar.Script.OperationCompleteEvent>,System.UInt64>T1T2T3) : Sansar.Script.OperationCompleteEvent
Use in a coroutine to pause the script until an event happens. (Inherited from Sansar.Script.ScriptBase.)
  WaitFor<ARG1,ARG2,ARG3,ARG4> (Action<ARG1, ARG2, ARG3, ARG4, Action<Sansar.Script.EventData>,System.Boolean>ARG1ARG2ARG3ARG4) : Sansar.Script.EventData
Use in a coroutine to pause the script until an event happens. (Inherited from Sansar.Script.ScriptBase.)
  WaitFor<T1,T2,T3,T4> (Func<T1, T2, T3, T4, Action<Sansar.Script.OperationCompleteEvent>,System.UInt64>T1T2T3T4) : Sansar.Script.OperationCompleteEvent
Use in a coroutine to pause the script until an event happens. (Inherited from Sansar.Script.ScriptBase.)
  WaitFor<ARG1,ARG2,ARG3,ARG4,ARG5> (Action<ARG1, ARG2, ARG3, ARG4, ARG5, Action<Sansar.Script.EventData>,System.Boolean>ARG1ARG2ARG3ARG4ARG5) : Sansar.Script.EventData
Use in a coroutine to pause the script until an event happens. (Inherited from Sansar.Script.ScriptBase.)

Member Details

AgentScript Constructor

This constructor is called before any properties have been set. Override Sansar.Script.ScriptBase.Init() to initialize the script after properties have been set.

Syntax

[Sansar.Script.Interface]
protected AgentScript ()

Remarks

 

Requirements

Namespace: Sansar.Simulation
Assembly: Sansar.Simulation (in Sansar.Simulation.dll)
Assembly Versions: 1.1.0.0

AgentPrivate Property

The Agent API for the agent this script is attached to.

Syntax

[get: Sansar.Script.Interface]
public AgentPrivate AgentPrivate { protected get; set; }

Value

The Agent this script is attached to if the script is on an avatar, null otherwise.

Remarks

The Agent will be set before Sansar.Script.ScriptBase.Init is called.

Requirements

Namespace: Sansar.Simulation
Assembly: Sansar.Simulation (in Sansar.Simulation.dll)
Assembly Versions: 1.1.0.0

ObjectPrivate Property

The ObjectPrivate this script is attached to if it is attached to an object.

Syntax

[get: Sansar.Script.Interface]
public ObjectPrivate ObjectPrivate { protected get; set; }

Value

The scene object this script is attached to if it is attached to an object, null otherwise.

Remarks

For AgentScripts this is the Agent's ObjectPrivate of their avatar.

Requirements

Namespace: Sansar.Simulation
Assembly: Sansar.Simulation (in Sansar.Simulation.dll)
Assembly Versions: 1.1.0.0

ScenePublic Property

Basic scene information for the current scene.

Syntax

[get: Sansar.Script.Interface]
public ScenePublic ScenePublic { protected get; set; }

Value

The Scene this object is in.

Remarks

This value will be set before Init is called.

Requirements

Namespace: Sansar.Simulation
Assembly: Sansar.Simulation (in Sansar.Simulation.dll)
Assembly Versions: 1.1.0.0

AgentScriptExample download link:
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.