Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text is not a function #1314

Closed
SaintPepsi opened this issue Mar 22, 2016 · 8 comments
Closed

text is not a function #1314

SaintPepsi opened this issue Mar 22, 2016 · 8 comments

Comments

@SaintPepsi
Copy link

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);

@dhowe
Copy link
Contributor

dhowe commented Mar 22, 2016

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

@SaintPepsi
Copy link
Author

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);
    }
}

@pete-rai
Copy link

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.

@tafsiri
Copy link
Contributor

tafsiri commented Mar 22, 2016

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).

@SaintPepsi
Copy link
Author

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

@lmccart
Copy link
Member

lmccart commented Mar 22, 2016

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

@SaintPepsi
Copy link
Author

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)

@toolness
Copy link
Member

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 😁

P.S. - Welcome to Github and p5!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants