Creating Custom Classes

I'm sure there must be a way of creating custom classes, but I can't find an example anywhere. Let me show you what I need to do in order to get started.

The code below should construct two custom classes. The second is derived from the first.

// psudo code for a class constructor
class C_foo() : someDerived object
	var nVersion = 1.234;

	fuction getVersion()
		return nVersion;
// psudo code for a class constructor
class C_fooBar() : C_foo // derived from C_foo
	var sAuthor = "John Wayne";

	fuction getAuthor()
		return sAuthor;

I need to learn the correct syntax for creating class objects, and what they need to derive from.

Any help will be tremendously appreciated.



  • Richard HaseltineRichard Haseltine Posts: 55,242

    Try looking at the DS 3 scripting docs - there is soem discussion there

  • rbtwhizrbtwhiz Posts: 1,610

    In my signaure you will find a link to the Scripting documentation. I would recommend reading the Summary section, followed by the Background section, followed by clicking the Identifiers link in the Language Reference section and reading the Reserved Words section on the linked page (noting specifically that "class" is reserved for future use), followed by clicking the Moving from QSA to Qt Script link down in the External Sources section and reading the The Scripting Language section on that page. This should provide you with the information you seek along with a brief glimpse into the history of the inevitable "why?" question that often follows.


  • PraxisPraxis Posts: 123
    rbtwhiz said:

    ...The Scripting Language section ...

    That reference in particular is Gold!  Thank you Rob.

    Here is the direct reference for convenience:


  • Thanks to everyone who responded. The help you gave me tonight allowed me to cook up this simple example of what I had in mind.

    // Construct a custom class derived from Object
    myScene = new Object();
    // add a Scene object for convenient access
    myScene.scene = Scene;
    // add a variable placeholder for a camera = null;
    // add a function for loading a camera
    myScene.loadCamera = function(sCamera)
    { = myScene.scene.findCameraByLabel(sCamera);
    // End of class implementation
    // using the myScene class, load a camera
    myScene.loadCamera("Default Camera");
    // test the interface by retrieving the camera's focal length
    var focalLength =;
    // print result

    Now that we have defined this class, we can create another class derived from myScene, as shown below.

    mySuperScene = myScene;
    // add a couple of properties
    mySuperScene.x = 12;
    mySuperScene.y = 35;
    // add a function to retrieve the sum of x + y
    mySuperScene.getLength = function()
    	return mySuperScene.x + mySuperScene.y;
    // End of mySuperClass implementation
    // varify that the interfaces work
    var focalLength =;
    var nLength = mySuperScene.getLength();
    print( nLength.toString() );

    Once classes like these are fully implemented, you could save them to a script file and include it as a library module (see my previous thread on using Include statements).

    I believe there are lots of opportunities for building wrapper classes around DS objects, encapsulating a lot of low-level operations and exposing simple-to-use interfaces.

    Thanks for you help guys!



Sign In or Register to comment.