P5.js: text is not a function

Created on 22 Mar 2016  路  8Comments  路  Source: processing/p5.js

I might not be a pro at coding but i do know that i've used this function yesterday and i think around 14^14 times and nothing changed since yesterday. is it my fault or is this something that's wrong in p5?

full details:

draw @ sketch.js:71
p5.redraw @ p5.js:16412
(anonymous function) @ p5.js:11813
(anonymous function) @ p5.js:11714
p5 @ p5.js:11976
_globalInit @ p5.js:8482

the p5.js editor gives a different error:
72: Uncaught TypeError: string is not a function

The line of code that's being the problem:
text("test",100,200);

Most helpful comment

I guess what I did is good then in a way?

Absolutely!! I really like it when problems like this are reported b/c it makes us brainstorm ways we can help ensure that users of p5 don't get frustrated in the future :grin:

P.S. - Welcome to Github and p5!

All 8 comments

can you include the simplest bit of code that demonstrates the problem, and also list the version of p5.js you're using? thanks

p5 version : 0.4.23
This is where the text function is:

function draw() {
    background(210,210,210);
    fill(0,0,0,100);
    textSize(15);
    for (var i = 0; i < population.length; i++) {
       text("test",100,200);
    }
}

Do you perhaps have a name clash between a variable in global scope and a p5 method? This will generate the very error you see.

I think @pete-rai is correct, a line like text += possible.charAt(Math.floor(Math.random() * possible.length)); would effectively overwrite the text function by converting it to a string (and appending some stuff to it).

What @tafsiri says is right. I think I have something like that in my code I didn't realise that would break it.

thanks all for your help debugging. maybe there is some warning we could raise if a user tries to overwrite a p5 function? or maybe we just need more documentation making it clear this will break things. cc @toolness

Wow this community is really awesome :o,
I guess what I did is good then in a way? Because finding bugs or problems is really nice
(My first time on github)

I guess what I did is good then in a way?

Absolutely!! I really like it when problems like this are reported b/c it makes us brainstorm ways we can help ensure that users of p5 don't get frustrated in the future :grin:

P.S. - Welcome to Github and p5!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stalgiag picture stalgiag  路  3Comments

b0nb0n picture b0nb0n  路  3Comments

ogoossens picture ogoossens  路  3Comments

aman-tiwari picture aman-tiwari  路  3Comments

slowizzm picture slowizzm  路  3Comments