Invalid Code Works / Valid Code Fails
void setup(){
size(160,120);
}
void draw(){
background( getColor() );
}
public color getColor(){
return color(0, 255, 0);
}void setup(){
size(160,120);
}
void draw(){
background( getColor() );
}
void getColor(){
return color(0, 255, 0);
}When you run this code in native Processing, the public function getColor() will return a color array data-type, containing the RGB value of green. Unfortunately this does not work in Processing.js and causes a JavaScript error that stops other Processing.js scripts from running. I believe may be a result of a parsing error.
You can "fix" your code by replacing all your public functions with a void function. For example: you can replace function declarations that look like this public datatype function() { return value; } with declarations that look like this: void function(){ return value; }.
Even though your function is void it will return any data-type you feed into the return line. Using this 'fixed' code will not allow you to run your Processing code natively.
The green (valid) code works in Native Processing and fails in Processing.js. The red (invalid) code works in Processing.js but fails in native Processing.