Is there any way to save/read cookies in the p5.js and p5.play libraries in JS? I'm making a proof of concept for a saving mechanism and I can't find how to save/read the cookies.
-
https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie – Mystical Oct 21 '19 at 16:07
2 Answers
If you only want to save data locally and have no intent to communicate that information back to a server (e.g., for authentication or identification) you may want ot use localStorage
instead of cookies.
p5.js has a simple storeItem
/getItem
API that is basically a wrapper for localSotrage
but it's a bit better: localStorage
only works to store strings, but p5.js's API understands how to serialize and deserialize objects (and in particular p5.js data structures) as well.

- 112,806
- 17
- 235
- 239
-
Oh cool I've never seen the `storeItem()` and `getItem()` functions before, thanks! – Kevin Workman Oct 21 '19 at 18:49
p5.js is "just" JavaScript, so anything you can do in JavaScript, you can do in p5.js. That means if you can't find what you're looking for in the p5.js reference, you can often Google for a more general JavaScript solution.
In your case, try googling "JavaScript save and read cookies" for a ton of results.
I would start here:

- 41,537
- 9
- 68
- 107