Open Source Platform
for interconnected virtual worlds

Content Scripting Python Introduction

From RexWiki

Contents

Background

realXtend adds Python script support for the server using Ironpython. The script uses a different kind of system compared to LSL scripts which use the inventory system. This is because the scripts are more powerful and can also access the server machine's other resources. The scripts are stored in the server's ScriptEngines\PythonScript subfolders, not to database. By default this folder contains the RXCore folder which contains the core implementation of the script engine so this folder shouldn't be modified. Samples folder contains some example scripts.

python_folders.jpg

Objects & classes

The rex python script engine takes a different approach compared to the LSL scripting system. In rex python script engine every primitive and avatar in the world is an object. You can define which python class is tied to the primitive. If you don't define your own class for a prim, then the default class "Actor" is used for it.
python_class_to_prim.jpg
Defining Python class for Prim using realXtend Viewer

Class hierarchy

The class hierarchy looks like this:

  • object (Python object class)
    • LSLObject (In rxlslobject.py, interface to LSL functions) (Source code)
      • Actor (In rxactor.py, implements rex specific functionality, default class for prims) (Source code)
        • Avatar (In rxavatar.py, implements rex avatar specific functionality) (Source code)

Python script engine features

  • At the moment the python class of the prim can be changed on the fly. Internally the script engine deletes the old python object of the prim and creates a new one with the newly defined class.
  • Automatic script reloading when a script has changed is not supported. However, the python script engine can be restarted on the server by typing command "python restart" to the server console. This command first deletes all python objects, reloads the scripts and then creates the objects again.
  • Any class you create should be inherited from Actor class. The class hierarchy for any custom class is then "object->LSLObject->Actor->CustomClass"

Available functionality

When doing python scripting you actually have the following functionality in your fingertips:

1) The python script implements the LSL script interface which means that most of the LSL functions can be used in the script. All LSL functions are not supported because they haven't been implemented in the server's c# code yet.

2) There are also some additional script functions which have been implemented inside the server and are callable from the python script. Check out the RXCore\rxactor.py and RXCore\rxavatar.py files for details about the additional script functions.

3) You have most of the Python's functionality at your disposal. A note for regular Python users, Ironpython doesn't support all the functionality of the regular Python at the moment. Some of the standard library modules work and some not. For more information about Ironpython go to http://www.codeplex.com/IronPython

4) Ironpython supports c# stuff so you can for example create objects defined in c# dll's, then call their functions and do other kinds of c# stuff in the python scripts.

Python tools, tutorials

You can use notepad or any other text editor to create python scripts. There are also many IDE's available, one that we have used, is pretty good and also free is called PyScripter and can be downloaded from http://mmm-experts.com/Products.aspx?ProductID=4

Some other Python resources are:
Python Library Reference
Python Reference Manual