We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am making a game with Processing 3, and it runs perfectly in the PDE; although, when I export the application and run it, the game freezes when a certain method is called: gameOver()
. The gameOver()
method is called whenever the player is hurt by an enemy (which is whenever an enemy touches the player).
The only thing that I can think of is that it loads an image, but I have used the add file button to add the image and everything.
I'm running macOS Sierra 10.12.6.
Here is the link to the code and applications. http://www.mediafire.com/folder/seq00jfeqsl69/Open_Desktop_Adventure
Answers
Could you just post the relevant code here?
You really should do all you image loading in setup(). Maybe your gameOver() function is being called every frame, and thus the image is being reloaded every frame? (This wouldn't happen if you loaded it in setup()).
I'm not quite sure which code is relevant, because the gameOver() method references other methods and variables that the program uses.
All images are loaded within setup().
gameOver is called every frame the player is touching the enemy, but the inside only executes every 30 frames after the method is initially called.
I hope this is relevant (these are fragments from different classes, not continuous):
https://Forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text
https://Processing.org/reference/String_equals_.html
I replaced every time I had a
String == String
with theString.equals(String)
, but it didn't fix the issue I am having.I've narrowed down where the source of the problem is by disabling different parts of the code, but the program only freezes when it decrements the playerHealth variable.
Aha! It appears as though I have made the simple mistake of forgetting to put some of the images in the data folder! It's working just fine now!
Congrats @thesuperdaine -- I love a happy ending. Thank you for telling us how it worked out.
If problems like this are really hard to track down then you can use try/catch blocks to print or log the error message to a text file. They aren't used much in sketches, but can be very useful for exported apps when all else fails.