Textwrap is not defined

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 :slight_smile:

1 Like

Hi @Omri,

Can you provide your code (or the specific part of it) where you try to use the textWrap function?

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 :wink:

1 Like

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?

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? :thinking:

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

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