Referencing a class using a string stored in another class?

I’m having trouble getting a class to reference a variable from another class using a string, it gives me the error ‘that the global variable “variableName” does not exist.’

How could I get this to work? For an example of what I’m trying to do I’ll see if I can write a bit of pseudo code with all the important bits.

//Class to grab the variable from
class main{
int class1Value;
main(int c1){
class1Value=c1;
}
}

//the class member to be referenced from main is input in 'inputString'
class grabber{
String refString;
int class2Value;
grabber(String inputString){
 refString=inputString;
}
void update(){
class2Value = refString.class1Value;
}
}

Any way I can do this without any errors?

imo make a hashMap in main and in grabber use the String as a value to get the value from the hashMap

see reference

1 Like