Pointers, references and variables
in
Programming Questions
•
1 year ago
Excuse the incorrect use of terms. I have a vague sense that these are related to my question so thought they would be an apt title.
Basically, I am unsure how to say:
- a=x;
- b=a;
Then change x without b changing. I want b to what a was when I said b=a and stay that way until I manually tell b what it is later.
If anyone's interested in the reason: I want to follow a trail of pixels on an image I've loaded. Given a certain coordinate on the image, I want to search all 8 pixels surrounding it and see if any match a labled colour, indicating it is the next step on the path.
I don't want the path to be confused by the pixel it last came from or itself, so I rule these out with if statements. To store the pixel we last travelled from, I have a PVector array of 'previousPoints'. I consistently update this by:
- previousPoints[i] = currentPoints[i];
- currentPoints[i] = newly discovered pixel matching labled colour.
But, as you can see, when currentPoints[i] gets updated, it changes what value previousPoints[i] is equal to.
1