noc-book-2
noc-book-2 copied to clipboard
Where `createVector()` method can / must be called inconsistency?
I wasn't sure about the note in margin on page 43. Having just tried it, I'm now confused myself. In some sketches I can call createVector() outside of setup() and in others, like the one below, it has to be in setup(). I thought it might have to do with declaring the associated global variables of position and velocity at top of file, but that doesn't seem to change anything.
In the end, from a reader's standpoint - my preference would be for just taking out one or the other references to it (personally I like it in margin of example where it can't be glossed over.)
Page 40, first paragraph ("can't" bold mine)
...I should note that p5.js functions such as
createVector()can't be executed outside of setup() or draw()...
Page 43, Example 1.2 (around line 6 -- in margin note)
Note that
createVector()has to be called insidesetup.
Ah, thanks for this comment! I agree this is confusing! I have to think about how to best address it. createVector() can actually be called anywhere in the code! As long as that code is not being executed before setup() when p5.js is guaranteed to have been loaded.
Another minor nit with the comments in this example: they use second person ("you"), which is inconsistent with the rest of the book, which uses first person singular ("I"). If you are going to change the comments here, you might want to fix that.
(I also observe that the comments in the web editor code for this example are different from both of these: they use first person plural ("we")!)