Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where createVector() method can / must be called inconsistency? #1035

Open
brandtryan opened this issue Oct 12, 2024 · 1 comment
Open

Where createVector() method can / must be called inconsistency? #1035

brandtryan opened this issue Oct 12, 2024 · 1 comment
Assignees

Comments

@brandtryan
Copy link

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 inside setup.

image

@shiffman
Copy link
Member

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.

@shiffman shiffman self-assigned this Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants