We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have this code.
What happened now is that when I increase the value of i the value of test.i will always be the same as it was first time assigned.
What I want is that when I update the value of i the value of test.i is also updated.
I was thinking perhaps assigning the address reference instead of the value will solve this problem. But how can I do this in Java/Processing? Is there any alternative rather than assigned the value over time (the Test object will be around ~1000 in amount)?
Answers
The code is short enough to show in this forum and it will make it easier for members to discuss it, so here it is
Unfortunately for you its is not possible to link the
i
in Test to the globali
Java does not support C style pointers. Since you want these 2 variables always to have the same value why have them as separate variables?How can I use one variable for several different classes?
Let say I have a private function named PrivateFunction(int _i){} in Test class. How can I get int _i filled from a value outside of Test class?
Meta question, how can you show code in this forum?
http://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text
If you really want to pass a only a reference, you could create an array of length one. Unlike primitive datatypes, arrays and objects are passed by reference.
But i don't have any idea where this could be useful at the moment.
Some pedantic observations: :-B
[]
operator.In Processing any class defined inside a pde tab is an inner class so has access to any variables declared in the sketch. The sketch below 2 classes sharing the same variables.
The output was
Cool! Okay, now if I want to pass primitive data - type I just need to make it a global variable. However, if the data - type is an object it will automatically pass a reference instead of value in Java.