Open Source Platform
for interconnected virtual worlds

Content Scripting Python Typical Class Structure

From RexWiki

Here's a typical python class saved in fictional scaling.py named file:

import rxactor
import rxavatar
import sys
import clr

asm = clr.LoadAssemblyByName('OpenSim.Region.ScriptEngine.Common')
Vector3 = asm.OpenSim.Region.ScriptEngine.Common.LSL_Types.Vector3

import random
import math

class ScaleTest(rxactor.Actor):
    def GetScriptClassName():
        return "scaling.ScaleTest"

    def EventTouch(self,vAvatar):
        scalex = 0.5 + random.random()
        scaley = 0.5 + random.random()*2
        scalez = 0.5 + random.random()*3
        tempscale = Vector3(scalex,scaley,scalez)
        self.llSetScale(tempscale)

Import

What other files are imported and used in this class. These can consist of Python classes and in this case also a C# type named Vector3 is loaded from a C# assembly.

Class

The name of the class and in parenthesis which class is the parent class.

Functions

All classes should override GetScriptClassName function which should return the filename+classname. Other than that, you can add new functions, override some functions (like EventTouch in the above example is used to scale the prim when someone touches the prim) and so on.