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//ctorfunction CBase(){	this.valueA = 10;}CBase.prototype.dump = ?virtual? function()  //...how to declare as virtual?{    print(this.valueA);}///////////////// CDerived//ctorfunction 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: 885

    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: 885

    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: 885

    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: 250

    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_2762644peter_2762644 Posts: 53
    edited February 2018

    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_2762644 on
  • PraxisPraxis Posts: 250

    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

  • f7eerf7eer Posts: 123
    Praxis said:

    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.

     

    Thanks very much for posting this. The code and references are very, very helpful, particularly the part about the constructors, because that is the immediate problem I am trying to solve.

  • PraxisPraxis Posts: 250
    f7eer said:

    Thanks very much for posting this. The code and references are very, very helpful, particularly the part about the constructors, because that is the immediate problem I am trying to solve.

    You're welcome!  This technique still works well for me.

    If you want to implement some classes as separate .dsa script files, you may find these useful too:

    https://www.daz3d.com/forums/discussion/269626/classes-and-separating-script-files

    Bug since DS v4.11.0.236 DzSIReloadAction: Sets getScriptFileName() == ""

    P.

  • f7eerf7eer Posts: 123
    Praxis said:
    f7eer said:

    Thanks very much for posting this. The code and references are very, very helpful, particularly the part about the constructors, because that is the immediate problem I am trying to solve.

    You're welcome!  This technique still works well for me.

    If you want to implement some classes as separate .dsa script files, you may find these useful too:

    https://www.daz3d.com/forums/discussion/269626/classes-and-separating-script-files

    Bug since DS v4.11.0.236 DzSIReloadAction: Sets getScriptFileName() == ""

    P.

    Yes, I ran across the 'separate .dsa script file' discussion, and I am finding that very helpful as well. I never use the DAZ script IDE, so I never ran into the getScriptFileName() issue, and I therefore always use absolute paths. I am working on separating my debug and math libraries into independent include files. It's almost a little like working in a real, predictable and repeatable software development environment!

Sign In or Register to comment.