I have a problem and I’m trying to figure out the best way to approach it. I have a list of objects in an array, order matters. I would like to create sub-groups of those objects. Ideally, this would just be a matter of picking out objects that I want to group and add them to different arrays. However, I need to ensure any changes that happen to the objects in the other groups are reflected or updated in the main group, so that I can save the contents of the array.
The other option is marking each object with a category value. I tried that first, however perhaps my implementation was poor. I ended up running into a lot of difficult to solve problems which would be easier if didn’t have to deal with all the objects at once.
What i understood is that you Need maybe 3 arrays. One with all Objekts, one with ‚just the small ones‘ and one with the ‚big ones‘, or similar, right? If so, you can just check through the Main object array and See if it’s ‚small‘ and then add it to the small Objects array. This method does not work for primitives! (Int float double and so on) because they are not referenced, But copied automatically when assigned to a variable. While objects such as pShape for example are referenced. So just a reference to the object is set to the Variable. You can See this by looking at this :
PShape a = new PShape();
PShape b = new PShape();
PShape c = a;
PShape d = copy(b); // Note that in this case copy() might not actually exist for pshape, But just as an example
and then if you Print it, it becomes this :
a = ref$0000 // Looks similar, But not exactly like that.
b = ref$0001 // a new object, so a new reference
c = ref$0000 // reference to a
d = ref$0002 // a new object, with the data of b
That just demonstrates how printing a PShape Looks like. Same works inside arrays. This also means, that if you change c, it changes a, But if you change d, it does nothing to b.