I can’t see why the value of pressLoc is constantly updated to the mouse PVector while the mouse is pressed and dragged around.
Can someone please help me?
Does pressLoc = m create some kind of persistent “link”? I don’t understand how pressLoc value is being changed when those conditions aren’t true anymore.
pressLoc.set(m) takes the values of m and applies them to pressLoc
If pressLoc is (5, 7) and m is (10, 15), then afterwards pressLoc is (10, 15)
On the other Hand :
pressLoc = m sets pressLoc to be m (not equal to, but actually be!)
Meaning, if pressLoc was (5,7) and m is (10, 15), then afterwards pressLoc is m.
So if you change m to (100, 90), then pressLoc will be (100,90).
Or more obvious :
pressLoc = new NamedPVector(“PressLoc”,5,7)
m = new NamedPVector(“M”, 10, 15);
pressLoc.set(m) //does the same as pressLoc.x = m.x, pressLoc.y = m.y
pressLoc = m; // println(pressLoc.name) prints („M“)
Or again in other words, pressLoc = m sets the PVector object pressLoc to be the PVector object m. So any changes to m will obviously be also shown if you access m through pressLoc.
I really like PVector.set() But unfortunately I have developed an aversion to it because in the iCompiler, due to some bug, using it sometimes results in the z value remaining “undefined.” So I find myself humming NaNNaNNaN a lot.
Never happend to me in the iCompiler, but i still tend to avoid .set, because it doesn‘t really work well all the time for me… just like .add, .sub and mult and div… and they also don‘t allow followups like .add().mult()… which should work in the IDE, if i‘m not mistaken…