Re: Collision Check Error
Can you show the console showing what you have printed out as debug trace?
I don't see any println() statements in the code you've posted.
Quote:
some things I've done might not be fully self-explanatory
Program comments would help there. Put the comments in the program and then anyone can understand without having to ask you.
Re: Collision Check Error
Quote:
Can you show the console showing what you have printed out as debug trace?
The game runs as an applet and for some reason println() doesn't seem to work with it, so instead I draw the debug messages to the screen.
I'll just play the game a bit until I get an error to give an example of the errors it gives:
"Start of second loop: 5, 6"
"Start of second loop: 12, 11"
"Made dead enemy"
"Start of second loop: 2, 36"
"Start of second loop: 10, 17"
"Start of first loop loop: 0"
"Start of first loop loop: 5"
As you can see it isn't always the same error, or even the same place in the code that it freezes each time.
I've just updated the code in the first post to include comments that explain what is going on.
Can anyone help me?
Re: Collision Check Error
The println() output goes into the browser's Java console.
Sorry, your output example list makes no sense. I don't know what is an error vs normal output.
Perhaps if you added some more text to the messages: "i=" + i and "ii=" + ii
to put labels on the values shown
Re: Collision Check Error
Normal output would be "First loop broken" because this is at the end of the code, so when it is running normally it displays "First loop broken".
However, when the game freezes, it displays a different message (examples are the ones in my previous reply).
I think this means that the game is freezing in between the code and that it can't reach the end of the code because the message doesn't change (hence why I think the error is in that part of the code).
Do you understand now?
Re: Collision Check Error
Normal output would be "First loop broken" because this is at the end of the code, so when it is running normally it displays "First loop broken".
However, when the game freezes, it displays a different message (examples are the ones in my previous reply).
I think this means that the game is freezing in between the code and that it can't reach the end of the code because the message doesn't change (hence why I think the error is in that part of the code).
Do you understand now?
Re: Collision Check Error
Code :
if (ii>=totalenemies) break;
message = "Second loop broken";
Can you explain what the message means? It looks like the message is output if you do NOT break.
A better debug would be to show ii:
message = "Second loop broken ii=" + ii;
Re: Collision Check Error
If your explanation were included in with the output to show which ones show what, it would help.
Having to scroll up and down as I read your later postings to see what you are talking about makes it hard to follow.
Re: Collision Check Error
Okay I've updated my first post to show some of the error messages.
And the whole "breaking the loop" thing isn't actually necessary (because the for loop will end anyway) it was just something I put in in the vain hope that it might make a difference but it didn't so I've taken it out now to avoid confusion (because I know that's not where the error is).
Re: Collision Check Error
Ok, can you run a test now and copy the contents of the Java console and paste it here with comments showing where you think the problem is?
A hanging/freezing program usually is an unending loop.
Re: Collision Check Error
The console doesn't show anything, that's why I had to program my own debug messaging thing (basically just "message = 'string';" and "g.drawString(message,x,y);".
The errors I get are the ones shown in the first post.
Re: Collision Check Error
I've told you already it doesn't seem to write anything to the console which is why I programmed my own debug messaging into the code so that I could see whereabouts it was freezing.
If it helps I'm using BlueJ to write, compile and run my code and my computer is an iMac running Mac OS X.
Re: Collision Check Error
OK, I know nothing about an iMac.
Do you have any command prompt windows for running java from a commandline so you can see println() output?
Re: Collision Check Error
There is a terminal but I've never used it.
When I want to run my code I just use the run option in BlueJ
Re: Collision Check Error
Oh wait I've figured out how to use the console but it gives me a reallyyyyy long message, shall I copy and paste all of it?
Re: Collision Check Error
Well for now, can you copy the first 20 and the last 20 lines with ... between to see if it could have any useful information.
Re: Collision Check Error
Well I've had a look and the message it shows when the game freezes is this:
Code :
Exception in thread "Thread-21" java.lang.ArrayIndexOutOfBoundsException: 19
at Main.run(Main.java:192)
at java.lang.Thread.run(Thread.java:637)
Although it is sometimes slightly different:
Code :
Exception in thread "Thread-25" java.lang.NullPointerException
at Main.run(Main.java:192)
at java.lang.Thread.run(Thread.java:637)
Thank you for your helps so far.
Re: Collision Check Error
Those messages look very important for helping you find your problems.
Re: Collision Check Error
Hmmm.. I can't make any sense of them though :/
How am I supposed to interpret console messages?
Re: Collision Check Error
The error messages you posted show what happened and where. For example:
Quote:
Thread-21" java.lang.ArrayIndexOutOfBoundsException: 19
at Main.run(Main.java:192)
On line 192 in Main there is an array index of 19 that is out of bounds (the array has too few elements)