Superclass and Subclass in Unity Javascript

So I wrote like below in unityscript and it worked for PC platform (Dynamic compile possible),

but I need to convert that for android, ios, so should change to Strict compile (#pragma strict),

Then how to revise this?

class CharactersCard{       // for all character's general

    var skillType : cardSkillTypes; 

}

class GrndMgSkillCard extends CharactersCard{   

    var byDefaultVal : boolean = true; // use default values? 

    var element : elements;

    var fireCrds : fireCards;

    var iceCrds : iceCards;

    var windCrds : windCards;

    var earthCrds : earthCards;

    var otherCrds : otherCards;

    var buffCrds : buffCards;

    var guardCrds : guardCards;

    var myCard : GmCard ;    

}

 

var auxPlyrCrds : CharactersCard[];

 

for(var z : int = 0 ; z < auxMxCrds ; z++){ 

   if(auxPlyrCrds[z].myCard.guardSkill){

.....

...

error : myCard is not a member of ‘CharactersCard’

Your problem is just inheritance. myCard is a member of GrndMgSkillCard but your array sís of type CharacterCard so automatically the compiler does not know about it.

What you could do instead is either put myCard in CharacterCard or use virtual methods.

Moving it up is more natural since you seem to expect myCard to be found on the top class.

The virtual way goes:

class CharactersCard{       
    var skillType : cardSkillTypes; 
    virtual function GetMyCard(){}
}

class GrndMgSkillCard extends CharactersCard{ 
    var myCard : GmCard ;
    virtual function GetMyCard(){
        //Do something with myCard
    }
}

But this second approach is not really intuitive. The top class is not supposed to know about sub class member and should not include anything that could potentially exist below.

I would opt for the moving of myCard up to the top class.