Sketch not working on JavaScript Mode

edited January 2014 in JavaScript Mode

The sketch: http://www.openprocessing.org/sketch/128150 It works fine in Java mode but God knows why it does not work in JavaScript mode. At the beginning it takes my keyboard input but shortly after it does not. It is getting me frustrated.

Answers

  • Answer ✓

    Your URL results in 404 Page not found.

  • Hi mbraendle, I just updated the link.

  • _vk_vk
    edited January 2014

    Spotted some things, not sure if they are the cause of failing in javaScript mode though...

    • Don't compare Strings using ==, use .equals() instead

    • In line 367 (pasted in IDE) i think you want a && instead of &.

    • A side note you don't need to do if(someMethod() == true), if(someMethod()) has the same result and is cleaner to read and write.

    • Another... to make a boolean change from the state it is to the other (toggle true or false) you can use myBoolean = !myBoolean, easier : )

  • In line 367 (pasted in IDE) i think you want a && instead of &.

    Java overloads operators (&, |, ^) to also accept boolean operands! L-)

  • And javaScript? Won't this make it confused? I really don't know...

  • edited January 2014

    And JavaScript?

    In JavaScript, as many C-like languages, any value can be interpreted as either true or false.
    So, it's even more permissible than Java by far! :bz

    image alt text

  • tks ; )

  • Thanks for the help but the program is still not working on JavaScript Mode. :(

  • In PJS, you should not use names of Processing functions as variable or class names. In your code, you use "second" as a variable name, but second() is a Processing function.

    See processingjs.org/articles/p5QuickStart.html#variablenamingcare

  • edited January 2014

    In PJS, you should not use names of Processing functions as variable or class names.

    That's very true advise in general. Even in Java is a bad practice itself! :-q
    Although, in a lazy practical sense, if he ended up never invoking second(), there'll be no running consequences! >:)

  • dear all,

    I am porting all my Processing source code from running Java-applets embedded in a HTML-driven environment, to Processing JavaScript generated webcontent...

    I had several reasons to do that, first of all the restrictions under the high level security of the latest Java software. My 'webcontent' cannot run unless it can be trusted.

    Second, some of my older sketches cannot run under newer releases of Processing itself (!)- probably due to some of the dinosaur programming I still carry around ;)

    So I had to upgrade anyway. I decided to port all my sketches to JavaScript, why not. I even starded a new Wordpress blog/site platform, to release some of my sketches...

    And also I ran into numerous amounts of trouble... here is a list...

    • be sure to put size(900,540) in your setup() void in the main sketch, as a minimum; JavaScript needs this to set up the display region on your webpage...

    • do not use too much 'exotic' embedding of classes; this will work fine under Java, but JavaScript is bound to have some issues with that...

    • for the same reason, do not carry too much data around - and I mean clear storage variables... recursion works fine, as long as you store not too much...

    • if you can, use the main draw() void for drawing intermediate or final results; in most cases: if your draws are hidden inside embedded methodes/classes - so not in sight of the main draw() - they will most likely not show up...

    for those who want to have a peek at my working - mostly recursive - examples, visit http://kilroywashere.nl/

  • P.S. And yeah, most of my sketches will not run under JavaScript, and some of them not under Processing to start with... and it all worked... luckily I can still run version 1.5... ;)

Sign In or Register to comment.