My sketch is not running on open processing

edited February 2014 in JavaScript Mode

Hi, I'm new and did a co-coded project that I'd like to upload on the open Processing forum. It's not running though and I'm not sure what the problem is...here is the link to the sketch.

http://www.openprocessing.org/sketch/132319

can anyone help?

Thanks!

Answers

  • edited February 2014

    1st rule for JavaScript: never have a variable & a function sharing the same name!!! b-(
    Inside function steer(), you declare a local variable called steer too!!!
    Rename that to something like steering or whatever! *-:)

    Even after that, JS complained about the renamed steering and another variable called desired as being undefined (TypeError)!

    Found out that you were using PVector's method sub() w/ 2 PVector arguments.
    Its most correct usage in that case is by invoking it as static; that is, using the class's own name instead of a variable:

    desired  = PVector.sub(target, loc);  
    steering = PVector.sub(desired, vel);
    

    Check sub()'s reference:

    http://processing.org/reference/PVector_sub_.html

    Another way is putting the recipient PVector variable as 3rd argument:

     PVector steering = new PVector(), desired = new PVector();
    
     PVector.sub(target, loc, desired);   // subtract target - loc and store result in desired
     PVector.sub(desired, vel, steering);
    

    Even though Java doesn't mind, like the case of having function & variables sharing same name, JavaScript crashes!!! [..]

Sign In or Register to comment.