Pass INT from class back to global
in
Programming Questions
•
1 year ago
I am having trouble passing a variable from a function inside of a class back out to its public variable. readRX is initialized 0, and then gets changed to 5 within the class. however, it does not change the public variable, readRX to 5.
If you rin the program, it will successfully print r as 5, but readRX will always read 0.
On a related note, (sorry the example is not here) passing a float[] into the class, not an int, will change the global float[] variable.
How do I pass a variable from a class back into the global environment?
- Class nmz;
- int readRX = 0;
- void setup()
- {
- size(1110, 256);
- }
- void draw()
- {
- nmz = new Class(readRX);
- nmz.RX();
- println(readRX);
- }
- class Class{
- int r;
- Class (int readRX) {
- r = readRX;
- }
- void RX(){
- r = 5;
- println(r);
- }
- }
1