Help with GetType().GetField().GetValue()

Hello People!

I’ve find a solution to read variable values from a string, but my code does not work… its have error all time, what I’m missing? or What is wrong?


LoadedREsource is a string name, and when i use


Is exactly what i need, but this is not the problem, the line remains with the red mark of “incorrect”…
Anny help?

Thanks guys!

Good day craftingtycoon !

I think you are missing the object in the GetValue. You need to say what object contains the variable. In this case i supose is “this”. So you need this:


Aaaand in case you want to SetValue(), you will need to write the GetValue sentence inside the SetValue() like this:

this.GetType(int).GetField("Resource"+LoadedResource).SetValue(this.GetType(int).GetField("Resource"+LoadedResource).GetValue(this), NewValue);

If hellped accept the answer :smiley: