Grabbing a value using a string in the reference

The probable reason for me not being able to find the answer when searching is my lack of knowledge when it comes to coding terms and expressions.

public Vital Strength;

Declaring a Vital called Strength.
All good so far.

Strength = new Vital(5, "Strength");

Here I am creating the Strength vital by calling upon the function Vital,
passing the integer 5, and the string “Strenght” as arguments.

public Vital(int _valueMod, string _statName)
{
    currentValue = Player.current._statName.currentValue * _valueMod;
    maxValue = Player.current._statName.currentValue * _valueMod;
}

Here is where it (obviously) does not work. My Player class has no declaration for
_vitalName(because it wouldn’t do anything, I can’t grab the currentValue out from a string).

I want to grab a currentValue from a Stat, using not the direct reference to the Stat(as this would not make it useable for more than 1 stat as I would have to manually type the name of a Vital) but a reference that can be changed in the Call arguments.

Is this possible?

A “simple” way to do what you want is to use a System.Collections.Generic.Dictionary<string,Vital>. The, you could use the following syntax :

Player.current[_vitalName].currentValue

See Dictionary<TKey,TValue> Class (System.Collections.Generic) | Microsoft Learn

I think that the concept of reflexion could help you but I absolutely don’t know how to use it.