- Home /
 
Different way to access class variables?
I am trying to write a program that is a DnD Character generator.
I am having some issue with getting the feats to work the way I want them to though. Right now I have a Class array set up as the following
 var feats: Feats[]; //stores Feats in an array
 
 class Feats
 {
     var name: String; //name of feat
     var desc: String; //description of feat
     static var nameV: String = name; //for the purpose of calling on the feat outside of the class 
     static var selected: boolean; //determines if feat is selected is or not
 }
 
               I have a feat called "Toughness" that when selected will give the player +3Hp at first level.
The question I have is; Is there a way to call on that particular feat name and selected variable without having to use the array element?
Something along the lines of:
 if(Feats.Toughness.selected)
 {
      startHP = 13 + modCON;
 }
 else
 {
      startHP = 10 + modCON;
 }
 
               instead of
 if(feats[#].selected)
 {
 
 }
 else
 {
 
 }
 
               The reason I would like to do it the first way instead of the second is for ease of referencing them without knowing the element number in the array
Answer by Screenhog · Sep 05, 2012 at 05:30 PM
What about also having a class for the characters, and then including each feat manually?
 class Character {
   var name: String; //name of character
   var toughness: Feat;
   var stamina: Feat;
   var awesomeness: Feat;
   var dentalHygiene: Feat;
 }
 
               Then, you'd access it through the character itself:
 var myChar: Character;
 
 if (myChar.toughness.selected) {
   startHP += 3;
 }
 
              Your answer
 
             Follow this Question
Related Questions
Creating A Class Variable That Works With Any Class 0 Answers
Creating a dynamic array of objects of custom class 1 Answer
Editting a custom javascript class in the inspector 1 Answer
How to Typecast JS Variables as C# Classes? 0 Answers
Is it possible to create a script dinamic like animation>size controling the Elements variables? 1 Answer