We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I am having issues exporting a relatively large game I made to openProcessing. It contains a number of assets, including various images and a font. I do not import any libraries, and all the functions I used can be found in Processing's reference section.
I have exported other games to openProcessing that did not use any assets, and they all worked fine.
Any help would be greatly appreciated. Thanks!
Answers
Perhaps you should take a look at this:
http://processingjs.org/articles/p5QuickStart.html#synchronousIO
Thank you very much, I'll make sure to go through this.
Hello again, I have looked through the link you sent me, and did some of the things that were suggested, but I'm still not having any luck. I have a number of subclasses, and a decent amount of assets. I also didn't explicitly cast various division functions. Maybe it's one of those things?
Dunno what you mean by division functions. Nor what you mean by cast them! :-??
Inheritance is prone to conversion failings if we're not careful! :-SS
There are a number of issues of running PJS over a PDE sketch. I still plan to make a Technical FAQ article listing them.
What I got so far (from memory):
If your sketch uses the
import
statement, it won't work in PJS. It is true for Processing libraries (Minim, PDF, even more Serial!), for Java standard libraries (java.util.*, even more java.io.*!) or 3rd party libraries (controlP5 and others).That's why Processing removed implicit import of most libraries in the recent versions, you have to be explicit now. Only some classes are officially blessed (documented) like ArrayList and HashMap. You cannot use HashSet, and some classes that are automatically imported in Java code, like Integer.
Beware that JS has no concept of int variables, all of them are float behind the scene. So in Java, 2 / 3 gives 0 but results in 0.66666... in PJS!
Don't use the same name for a function and a variable. If you write
int draw = 1;
your PJS sketch will fail! The corresponding function will disappear.Likewise, there is no concept of function overloading: you cannot define both f(int x) and f(int x, int y). You have to give them different names. This is also true for class constructors, for example.
As said, inheritance can fail in some cases, particularly when extending a Processing class like PVector (better use composition instead). Probably because these classes are defined in JS directly.
If you think of other pitfalls, mention them there, I will compile them in the wiki.
I made a JSFiddle example showing some the pitfalls described above:
http://jsfiddle.net/PhiLho/z7GL8/9/
Output in Processing:
fi: 666
Integer division: 0
One parameter call: 10
Two parameters call: 25
Doom
Output in JSFiddle:
fi: 666
Integer division: 0.6666666666666666
One parameter call: NaN
Two parameters call: 25
(and it is crashed)
All very helpful, thank you very much. I'll have to take another look at my code.