简体   繁体   中英

p5.js 27646: Uncaught TypeError: Cannot read property '0' of undefined

I was coding in JavaScript, p5.js and came across this error line:

It is also suspicious to me because my project does not have line 27646 anywhere.

"

Please post your code as an MCVE that we can copy and paste to run. When I try to run your code, I get an error because I don't have the font you're trying to load. Either include the font file or modify your code so we don't need the font file.

But just looking at your code, this sticks out to me:

for (var i = 0; i < particles.length; i++) {
  if (particle[i].radius < 0) {

Here you're looping over the particles array, but then using a variable called particle . This is probably a simple typo.

I'm also suspicious of this line:

r = particles.random();

Here you're setting a variable that you haven't defined yet.

When your code contains multiple errors like this, it usually means that you aren't testing in small chunks. You should really get into the habit of working in isolation, only testing one small part until you get that working perfectly. That also makes it easier to post an MCVE if you do get stuck.

Your problem is that your word1 string has a space in it.

textToPoints() doesn't handle non-printable characters.

Try a string with no space or split your string up into to strings and combine the points arrays afterwards.

On Line 1 You define:

var particles = [];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM