Simple explanation for a C# developer (classes/inheritance)

Hi @all,

For some purposes, I want to use (quite simple) inhertance in scripts an I saw this is possible, but a bit frustrating for me, because I can't find a complete reference for scripting. I 'm professional developer, but comes from the Windows C# world. Understanding Java-Script (or similar dialect) is surley not the problem. But where can I find a documentation of keywords (and so on) which are useable in DAZ-Script ??

The following example snippet should show, where I have problems:

CBase.superclass    = Object;
CDerived.superclass = CBase;

///////////////
// CBase

//ctor
function CBase()
{
	this.valueA = 10;
}

CBase.prototype.dump = ?virtual? function()  //...how to declare as virtual?
{
    print(this.valueA);
}

///////////////
// CDerived

//ctor
function CDerived()  : base()  //...how to call the base-ctor?
{
	this.valueB = 5;
}

CDerived.prototype.multiply = function()
{
	return this.valueB * ???.valueA;    //...how to access properties from base?
}

//overwritten dump():
CDerived.prototype.dump = function()
{
    base.dump();           //...how to call the base-function?
    print(this.valueB);
}

 

Thx in advance for answering smiley

Greets Peter.

Comments

  • jag11jag11 Posts: 684

    DAZ Studio uses Qt Script which is ECMA-262 compliant, Qt Script reference is here. Programming for DAZ Studio is like programming in JavaScript. Having a C# background you might wanna dev in TypeScript which is a strict syntactical superset of JavaScript by the same father of C#.

    My main IDE is Visual Studio 2017 for all the platforms, but for DAZ Studio I prefer to use Visual Studio Code.

     

  • jag11jag11 Posts: 684

    As for the answer in TypeScript you use:

    class ClassTracker extends PersistentMap {
    
        constructor(filename: string) {
            super(filename);
    
            /** If empty, inject default values */
            if (this.isEmpty()) {
                classList.forEach((name) => {
                    this.add(name, true, false);
                });
                this.save();
            }
        }
  • Thank you Jag for the fast response. Of cource, I've found references to Java Script and Qt  Script. But my problem is still, that all of them doesn't work in DAZ Script. In fact, I'm not even able to use the class keyword (see attached image).

    What I'm doing wrong or where is my mistake of thinking?? frown

     

    Unbenannt.JPG
    480 x 473 - 39K
  • jag11jag11 Posts: 684

    DAZ Script does not support class keyword. You might wanna start here.

  • Okay. Then I know what I'm able to do - or more precisely: *not* able to do indecision

    Thank you for claryfing that!

  • The Help>Scripting command in the IDE pane will take you to the script documentations, which includes both sample scripts and object references.

  • Yes, I know this reference and it's helpful, Richard. But unfortunately it's not an answer for problems like building a little complex class hierarchies.

    I'm wondering, how difficult it would be, to write and compile PlugIns with Qt (or anything else and maybe even in Visual Studio) only to export the classes, i need.

    Without UI - I don't need a complex UI and would implement it furthermore per script.

     

    DAZ is a hobby for me and I didn't plan to invest a lot of time to learn programing very complex for plugins and so on. Unfortunately my free time is very sparse  wink.

  • PraxisPraxis Posts: 28

    I also had trouble with inheritance when starting to use DAZ Script, until I found this tutorial: http://www.kevlindev.com/tutorials/javascript/inheritance/inheritance10.htm

    It has since been updated to this (which I've not yet read): http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm

    These tutorials are aimed at DOM (html) applications, so may be overkill for simple DAZ Script apps - I use a simplified version of those techniques, which have worked well for my purposes:  See the attached TestInheritance.dsa, which demonstrates a Person-Employee-Manager hierarchy.

    Note:

    • There may well be better ways to do this simply, so if anyone knows them I'd love to hear.
    • For commercial-grade programming I expect jag11's way would be much better.
    • I'm from a Delphi (ObjectPascal) programming background, so please forgive the lack of DAZ Coding Standards in this demo script.
    • Feel free to modify+use this script for any purpose.

    P.

     

    dsa
    dsa
    Test_Inheritance.dsa
    19K
  • peter.pernhoferpeter.pernhofer Posts: 32
    edited February 9

    That looks absolut great and is nearly what I'm looking for... 

    Of course not a perfect solution (thx good, that I don't have to develop professionally in a script language laugh)

     

    Thank you soo much, Praxis!

    I will use that for a while and share my experience ;-)

     

    edit: @Praxis:

    It pays off to read KevLin's updated site. It's much more easier wink

    Post edited by peter.pernhofer on
  • PraxisPraxis Posts: 28

    You are welcome.

    Yes - the updated tuorial is more elegant.

    Please do let us know how it goes, and any new tricks you learn!

    P.

  • I will do that!

    However, this will take a while. Unfortunately I'm currently not able to spent much time for it frown

Sign In or Register to comment.