Global variables vs Class variables ambiguity.
in
Programming Questions
•
10 months ago
If I use the same name variable in an object and as a global how do I access the global one from the class with the variable with the same name. Sorry if that is badly worded I will show some example code:
- int variable = 1;
- void setup() {
- Object object = new Object();
- object.function();
- }
- class Object {
- int variable = 2;
- Object() {
- }
- void function() {
- print(this.variable);
- print(variable);
- }
- }
Now this will print "22" when i want it to print "21" how do i access the global when I have a class variable with the same.
And some general explanations on how to use global and class variables will be highly appreciated too!
Thank you in advance.
1