Open Source Platform
for interconnected virtual worlds

NG Design Document/Viewer Architecture/Scripting

From Rex community wiki

Contents

Background

Viewer scripting or in other words client-side scripting is the execution of scripts on the client, not the server. It is generally the same technique as used in the web by running JavaScript in the web browser. Client-side scripting has the following features:

  • Faster to execute than server-side scripts because the script is executed on the client.
  • The script doesn't have any latency issues because it operates on the client-side.
  • Do not take any server resources because executed on the client.
  • Security is important! Client-side scripting is a powerful tool and for example in the web Javascripts have been used for both good and bad.
  • In OpenSim all scripts are executed on the server-side at the moment.
  • Often easier to write than C++.

Python as client-side script

Python is used as the client-side scripting language. Python is familiar to many programmers and it has the following features making it the logical choice:

  • Very clear, readable syntax
  • Strong introspection capabilities
  • Intuitive object orientation
  • Natural expression of procedural code
  • Full modularity, supporting hierarchical packages
  • Exception-based error handling
  • Very high level dynamic data types
  • Extensive standard libraries and third party modules for virtually every task
  • Extensions and modules easily written in C, C++ (or Java for Jython, or .NET languages for IronPython)
  • Embeddable within applications as a scripting interface

List of Python features from [1]

Security

Security is very important with client-side scripts. Scripts can be sandboxed so that they can't harm the person's computer and execute python commands considered harmful.

Where to use client-side scripting

  • When viewer has clientside objects which need logic, doing it with scripting is the right way to go. Writing world object logic with c++ is slow when logic needs to iterated many times during the development.
  • Any code which needs to be fast, like for example everything related to rendering, should be always implemented with C++.

Use cases

Continuous fireworks

  • When avatar enters world, object is created on the client and it has a client-side script property attached to it
  • Client-side script is downloaded from the server
  • Script execution is started on the client, creating 10 particle effects which exist on the client only.
  • After 10-20 seconds more particle effects are created and fireworks sounds are played.
  • Previous step is repeated until the user leaves the world.

UFO object circling the avatar

  • Another avatar enters the world and it has a client-side script property attached to it
  • Client-side script is downloaded from the place avatar has stored the script
  • Script execution is started on the client: UFO object is created near the new avatar. UFO location is updated 20 times a second by the script.

References

  1. Python
    (http://www.python.org)