Working With Scripts

Working with scripts

Scripts add interactive behaviors to objects in an experience. In Sansar, you can create, upload and add your own scripts in C#.

Script API documentation

For more information on creating scripts for Sansar, read our API Documentation.

Alternatively, you may also find the API Documentation within the Sansar program folder. You can find the documentation on your system using the following file path: Program Files > Sansar > Client > Script API > Documentation.

To stay updated on the latest Script API changes, see Script API updates.

Uploading scripts

If you are interested in uploading scripts written in C# (.cs) to your inventory from your computer, see Uploading items in Sansar for a step-by-step guide on the upload process. Note that you will receive a warning if your script makes use of one of the Restricted APIs.

Adding a script to an object

You can add scripts to objects in order to make them perform actions or interact with avatars and the environment. Currently, there are two ways to add a script to an object in a scene. For more information on these two ways, see Adding scripts to an object.

Note: As of October 31, 2017, objects do not need to be set to IsDynamic in order to trigger collision events. Additionally, animated objects may trigger collision events if their animation causes them to collide with another object or avatar.

Setting the script's parameters

Some scripts allow you to enter parameters to modify the way the script works. Each script is unique, so the name and function of parameters for each script may be different based on how it was defined by the script writer. For more information on setting a script's parameters, see Setting script parameters.

Standard scripts and example scripts

We have provided several example scripts in the Sansar client's install folder for you to use. You can find the example scripts by following the file path: Program Files > Sansar > Client > Script API > Examples.

You can also find some documentation (and some download links) for some of these example scripts at Example Scripts in Sansar.

Integrate the Sansar Script APIs into Visual Studio

To help you get started with scripting in Sansar, we have provided a project file, ScriptExamples.csproj, in the install folder which imports all of Sansar's APIs and example scripts into Visual Studio. It is located located in the Sansar install folder: Program Files > Sansar > Client > Script API > Examples. Simply open the folder in Visual Studio 2015 and the project will import the APIs and example scripts.

Have more questions? Ask in our Discord!

Last updated