We are about to switch to a new forum software. Until then we have removed the registration on this forum.
When I use createVector() to assign a vector object to a global variable I get an object error. I've been working around the issue by creating a custom object that contains the vector objects I need and assigning the custom object to a global variable. I'm curious why it isn't possible to assign vector objects to global variables, any ideas?
Answers
You might look at this discussion
At the P5.JS' "Necklace" sketch, "global" variable vel is assigned a p5.Vector from createVector():
const vel=Object.seal(createVector());
http://forum.processing.org/two/discussion/7294/why-doesnt-my-sketch-run-in-javascript-mode
So I don't get why you couldn't do the same! @-)
Thanks GoToLoop! Didn't think to seal the vector object, that works!
Oh, Object.seal() or Object.freeze() got nothing to do w/ it! :(|)
Those were my attempt experiments at making objects "immutable" in JS.
They can be removed w/o any side effects at all! :-j
const vel = createVector();
I guess I should have included some code, the issue I was having was that
was throwing me an object error. Actually now that I check, that isn't happening anymore today...
var
,const
, orlet
keywords!Either declare them at the top and then initialize them within setup():
Or declare & initialize them at the top: