We are about to switch to a new forum software. Until then we have removed the registration on this forum.
New to processing and I'm having trouble with syntax on how to set specific values (x, y, or z) in an arraylistof pvectors . simple example:
ArrayList<PVector> points;
points = new ArrayList<PVector>();
points.add(new PVector(1,2, 0));
points.add(new PVector(3,4, 0));
points.add(new PVector(5,6, 0));
points.add(new PVector(7,8, 0));
int i =2;
if(points.get(i).x - points.get(i).y < 0) {
// points.z(i-1) = 1; //obviously wrong
println(points);
}
I can get() pvector values easily out of the arraylist but have had no luck in setting specific values when the pvector is already in the arraylist. I have fiddled with a number of syntax variations of trying to update the specific value and variations using pvector set() to no avail. my project requires me to load the arraylist with pvectors (no problem), and then for loop through the arraylist (no problem) and set z value of pvector loop index(-1) depending on x and y values of pvector at loop index(1) (problem). Just can't figure out the syntax to change the z value at pvector index(-1).
Simplified example above and if I could figure out how to set pvector z value at arraylist index(-1), I would be golden. Have found lots of examples with set() and add(), but nothing showing setting of single value for pvector already in the arraylist.
Help is appreciated.
Answers
points.get(i-1).z = 1;
?Thank you. Definitely not obvious to use a get() to set.
Thanks, makes sense. As I reread the language reference it says that get returns an object. That should have been a good enough clue for me that it wasn't just a getter returning a variable in the pvector.