Omri
August 27, 2021, 12:30pm
1
Hey,
I’m trying to use the textWrap function but I got an error: “Uncaught (in promise) ReferenceError: textwrap is not defined”.
I suspect that the problem is maybe in the p5.min.js library, is that make sense? how can I check that?
here is the part with the libraries in my HTML:
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
<meta charset="utf-8" />
</head>
thanks
1 Like
Hi @Omri ,
Can you provide your code (or the specific part of it) where you try to use the textWrap
function?
Omri
August 27, 2021, 1:52pm
3
Hi @josephh , here it is:
textwrap(CHAR);
text("some text", 100, 100,200);
I think that the error is because you used textwrap
instead of textWrap
. Variables in JavaScript (and most other languages) are case-sensitive, so textwrap
and textWrap
are two completely different bindings, independent of each other.
So, to make your code work, replace all occurences of textwrap
to textWrap
.
1 Like
Thanks!
Most of the programming languages out there are case sensitive, meaning that any identifier with or without upper case letters is not the same.
It’s true for functions, therefore textwrap
doesn’t exist!
When you have any questions on the API, check the reference:
https://p5js.org/reference/
Specially the textWrap
function:
https://p5js.org/reference/#/p5/textWrap
Also note that this is a common convention in JavaScript to put function names in camelCase
1 Like
Omri
August 27, 2021, 2:25pm
6
Hi @Ariadne & @josephh , thanks for the answer.
I wrote here by mistake textwrap
and not textWrap
…
In my code its:
textWrap(CHAR);
text("some text", 100, 100,200)
and still I got the error:
Uncaught (in promise) ReferenceError: textWrap is not defined
sorry for the mistake
Ok my bad!
If you remove the call to textWrap
, do other p5 functions work?
Omri
August 27, 2021, 2:58pm
8
Yes, also I tried the textWidth
, textSize
, textAlign
and they all works.
I looked at the https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js
and I found there all of textWidth
, textSize
, textAlign
, but didn’t find the txetWrap
.
So maybe its not the right library or something?
All right, it’s the p5js version then!
Check the available versions on the CDN (last one is 1.4.0):
https://cdn.jsdelivr.net/npm/p5/lib/
https://cdn.jsdelivr.net/npm/p5@1.4.0/lib/p5.min.js
4 Likes
Omri
August 27, 2021, 3:32pm
10
YES!
It was that, thank you!
if someone is interesting:
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/addons/p5.sound.min.js"></script>
<meta charset="utf-8" />
</head>```
2 Likes