We are about to switch to a new forum software. Until then we have removed the registration on this forum.
For me int() doesn't work. I get an error saying that int is not defined. I am using the p5 editor. Is this an editor issue?
Create a very simple example that demonstrates this error and post it here.
When I create a sketch with nothing more than this:
print(int("10"));
I get: Uncaught ReferenceError: int is not defined
Just deleted my last answer because I tested in Java mode.
I believe that p5.js is pure Javascript so I suspect that it is an invalid Javascript statement, but I leave that to someone who likes the language to answer it. ;)
But I have taken the int() command from the reference docs.
parseInt() seems to work though.
If you just wanna truncate an operation, simply adding up | 0 to it can be faster than parseInt(): :-B
| 0
11*1.5 | 0
11/2 | 0
11>>1
Nevertheless, parseInt() is still useful to safely convert other types like String to int! (*) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
int
Including those w/ different radices like hexadecimal, octal, etc.! :P
Just to clarify. This is a link to the reference docs:
http://p5js.org/reference/#p5/int
But when I try it, I get an error saying: Uncaught ReferenceError: int is not defined
Guess you're gonna need to open an issue there: https://github.com/lmccart/p5.js/issues 8-|
I just did ;)
https://GitHub.com/lmccart/p5.js/issues/390
Answers
Create a very simple example that demonstrates this error and post it here.
When I create a sketch with nothing more than this:
print(int("10"));
I get: Uncaught ReferenceError: int is not defined
Just deleted my last answer because I tested in Java mode.
I believe that p5.js is pure Javascript so I suspect that it is an invalid Javascript statement, but I leave that to someone who likes the language to answer it. ;)
But I have taken the int() command from the reference docs.
parseInt() seems to work though.
If you just wanna truncate an operation, simply adding up
| 0
to it can be faster than parseInt(): :-B11*1.5 | 0
results in 16 instead of 16.511/2 | 0
or11>>1
results in 5 instead of 5.5Nevertheless, parseInt() is still useful to safely convert other types like String to
int
! (*)https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
Including those w/ different radices like hexadecimal, octal, etc.! :P
Just to clarify. This is a link to the reference docs:
http://p5js.org/reference/#p5/int
But when I try it, I get an error saying: Uncaught ReferenceError: int is not defined
Guess you're gonna need to open an issue there: https://github.com/lmccart/p5.js/issues 8-|
I just did ;)
https://GitHub.com/lmccart/p5.js/issues/390