(JS) using an array to create a type.variable statement?

Is there a way to use an array element to create something like pc.temp*.baseValue, where temp is the name of the type you want? That is, if you have an array (“str”, “dex”, “con”) you would actually be getting pc.str.baseValue, etc.? I tried using a function as a wrapper and a few other things but nothing seems to work.*
Thanks!
Matt

You mean a class?

class PC {
    var str : int;
    var dex : int;
    var con : int;
    function PC (str : int, dex : int, con : int) {
    	this.str = str;
    	this.dex = dex;
    	this.con = con;
    }
}

var joe = new PC(14, 5, 10);
print (joe.str);

–Eric

Are you wanting an indexer?

You can use a string or anything to do the lookup…

Indexers appear to be C# only, but that seems closer to what I wanted. If I have a class of type Stat and I make a Stat named “strength” that has a member variable called baseValue, I would like to be able to access it from a script using something like:

var statArray = new Array(“strength”, "dex’, “con”);

var temp = obj.statArray[0].baseValue;

I can post the actual code, but I hope this clarifies what I am trying to do.

Thanks!

EDIT: I figured out how to do what I wanted. You can make an array of the objects themselves. So you would do:

var statArray = new Array(obj.str, obj.con, obj.dex);
var temp = statArray[1].baseValue;

of course you could use a for loop to iterate through as well. One odd thing is that you can’t use ++ or – , but var = var + 1 (or var - 1) works fine.

Thanks again!
Matt