- Home /
Passing Object References Through Function
I've got a problem that I'm not sure how to solve. I have this method in a class which is like a variable getter. Since my variable is private, you only can access the variable VIA this function.
function getStat(statName:String){
return this.statName._value;
}
Supposedly this function would return the value of whatever STAT that is in "statName:String", but instead I am getting errors saying "Object reference not set to an instance of an object".
I just need to know how to pass the name of the variable in a function and be able to use that variable (that is in the object). It's similar to PHP when you have something like $$name in which the variable $name is the name of the variable.
Any help would be great!
You need to use a datatype that supports that kind of lookup. It'd be much more straightforward to use a dictionary or something. With what you are trying to do here, it'll always return the same value even if you got it working!
Unfortunately, I don't know how to do that in JS. If you want an answer in C# I can tell you exactly how to do it, though!
How would you do it in C# then? I assume it's possible to use different languages on the same project.