Hi,
Thanks for taking the trouble to click on this Topic.
I’m currently working my way thru Daniel Shiffman’s Learning Processing & the Nature of Code books, and have the following query about a section in the latter, chapter 2 (Forces), section 2.3, p.69.
He uses the following code for simulating the effects of wind on a bouncing ball (the wind is only in-effect when the mouse button is pressed):
if (mousePressed) {
PVector wind = new PVector(0.5,0);
mover.applyForce(wind);
}
My interpretation of his code (ignoring the line mover.applyFoce(wind;) is as follows: when the mouse is pressed, a PVector object named wind is created. If / when the mouse is pressed again, Processing then creates another PVector object, also named wind?
I would expect the code above to result in an error, because an object already called wind exists. However, there is no error, and the code runs fine. Could someone explain why this is the case, as I’m a bit confused. Does the instances of wind only last the length of the if statement? Clearly I’ve misinterpreted.
Any help etc. will be much appreciated.
Kind regards,
Scolty