CommandData

CommandData Class

Command events are generated by the client when input events occur.

Syntax

[Sansar.Script.Interface]
public class CommandData : Sansar.Script.EventData

Remarks

Command Default Key Binding
PrimaryAction F
SecondaryAction R
Modifier Shift
Action1 to Action0 Number keys 1 to 0
Confirm Enter
Cancel Escape
SelectLeft Left arrow
SelectRight Right arrow
SelectUp Up arrow
SelectDown Down arrow
Keypad0 to Keypad9 Numberpad keys 0 to 9
KeypadEnter Numberpad Enter

An example script for handling client commands:

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.Script;
using Sansar.Simulation;

public class CommandExample : SceneObjectScript
{
    #region ScriptParameters
    public readonly string EventCommand;
    public readonly string CoroutineCommand;
    #endregion ScriptParameters

    public override void Init()
    {
    // Subscribe to new user events;
    ScenePrivate.User.Subscribe(User.AddUser, NewUser);
    }

    IEventSubscription subscription = null;

    void NewUser(UserData newUser)
    {
        Client client = ScenePrivate.FindAgent(newUser.User).Client;

        // CommandReceived will be called every time the command it triggered on the client
        // CommandCanceled will be called if the subscription fails
        subscription = client.SubscribeToCommand(EventCommand, CommandAction.Pressed, CommandReceived, CommandCanceled);

        StartCoroutine(ProcessCommands, client);
    }

    void ProcessCommands(Client client)
    {
        try
        {
            WaitFor(client.SubscribeToCommand, "SomeInvalidCommand");

            // This is not expected to get hit as waiting on an invalid command should throw a WaitCanceledException
            Log.Write(LogLevel.Error, GetType().Name, "WaitFor on an invalid command did not throw!");
        }
        catch(WaitCanceledException)
        {
            //Ignoring this expected exception
        }
        
        // Wait until the client sends the CoroutineCommand pressed
        WaitFor(client.SubscribeToCommand, CoroutineCommand, CommandAction.Pressed);

        // The script will now get the EventCommand when released as well as when it is pressed
        IEventSubscription subscription2= client.SubscribeToCommand(EventCommand, CommandAction.Released, CommandReceived, CommandCanceled);

        // Wait until the client sends the CoroutineCommand released
        WaitFor(client.SubscribeToCommand, CoroutineCommand, CommandAction.Released);

        // Stop listening to EventCommand Pressed
        subscription.Unsubscribe();
        subscription = null;
        
        // Wait until the client sends the CoroutineCommand pressed or released
        WaitFor(client.SubscribeToCommand, CoroutineCommand);

        // Stop listening to EventCommand
        subscription2.Unsubscribe();

    }

    void CommandReceived(CommandData command)
    {
        Log.Write(GetType().Name, "Received command " + command.Command +": "+command.Action);
    }

    void CommandCanceled(CancelData data)
    {
        Log.Write(GetType().Name, "Subscription canceled: "+data.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.EventData.

Public Properties

[read-only]
 
Action CommandAction . The action which occurred.
[read-only]
 
Command string . The command which occurred.
[read-only]
 
SessionId Sansar.Script.SessionId . The client which generated the event.

Public Methods

override
ToString () : string
A string representation of this object.
override
ToString () : string
Generates a string representation of the EventData. (Inherited from Sansar.Script.EventData.)

Member Details

Action Property

The action which occurred.

Syntax

[get: Sansar.Script.Interface]
public CommandAction Action { get; }

Value

Remarks

 

Requirements

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

Command Property

The command which occurred.

Syntax

[get: Sansar.Script.Interface]
public string Command { get; }

Value

Remarks

 

Requirements

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

SessionId Property

The client which generated the event.

Syntax

[get: Sansar.Script.Interface]
public Sansar.Script.SessionId SessionId { get; }

Value

Remarks

 

Requirements

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

ToString Method

A string representation of this object.

Syntax

[Sansar.Script.Interface]
public override string ToString ()

Returns

A string representation of this object.

Remarks

The format of this string may change between releases.

Requirements

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


Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

0 Comments

Article is closed for comments.