I seem to have many difficulties with the while function, but here's a new one...
I have the following code, a quick check to get me the number of 'game_particles' that are 'alive' at the moment:
function Num_Particles_On_Screen() {
Ã, int particles_on_screen = 0;
Ã, int particle_check = 0;
Ã, while (particle_check < Particles_To_Use) {
Ã, Ã, if (game_particle[particle_check].alive == true) particles_on_screen ++;
Ã, Ã, particle_check ++;
Ã, }
Ã, return particles_on_screen;
}
As you can see, the while runs until it has exceeded the number of 'Particles_To_Use', and then returns the total number of those found 'alive'.Ã, However, when I run the function, I get an error because the while loop appears to be hung.Ã, I have assured that 'Particles_To_Use' is not a number above the while loop limit before noloopcheck needs to be used.
I tried placing a display command inside the while loop, after the line "particle_check ++;"
It displays "0, 1, 2, ... 998, 999, 0, 1, 2, ..."
'Particles_To_Use' is set to 1000 at this point.Ã, So, why on earch is the script jumping backwards and re-setting 'particle_check' to 0?!
I suspect the 'return' function, but the manual only refers to 'return' as a dialog command.
-Thanks for any help, Akumayo
I don't see why is reset the particle_check variable to 0, would you try to put in particle_To_use with a lower value than 1000? but i think that you should try to put the noloopcheck, and see what happens
Where do you call this? Repeatedly? Because, you define "particle_check = 0;" in your function, which is likely to cause your problem. I am sure that the return keyword doesn't have anything to do with that!
I don't know if I understand your problem correctly though, I hope this helps.
If this function is called many times inside a loop then you have a problem with the particle_check, because is put to 0 every time is called.
I added noloopcheck just now, to see. Ã, The script doesn't get hung, I think, I'm not sure. Ã, The effect is nasty. Ã, After a very long period of humming (about 8 seconds) and doing nothing, control returns to the normal script. Ã, I'm not sure what exactly is happening. Ã, I removed the noloopcheck. Ã, Then I changed the 'Particles_To_Use' value down to 200. Ã, It runs now, fine, looks good actually. Ã, So, I guess that particular variable should be kept low for now.
That still doesn't fix the problem though. Ã, What is resetting 'particle_check'?
EDIT:
Just saw other replies.
dkh:Ã, That may actually be the problem, with the way I had the display set up.Ã, I'm going to tinker some more and see what else comes up.Ã, The while shouldn't cycle over 1000 times, but it is anyway.
RE-EDIT:
Tinkered a bit. The while IS only running 1000 times. For some reason, the engine just THINKS it's running more than that. Maybe, as dkh said, because it's in repeatedly_excecute. I dunno, but that's the problem.
Perhaps you should send the variable particle_check as a parameter of this function and don't put it as local then try and look if the problem continues.
Maybe Ashen can give you a explanation about your question cause I have no one.
Such confidence in me! Shame it's misplaced.
I don't have any ideas beyond what Nathan suggested, declaring particle_check outside of the function. Perhaps add check so it's only reset to 0 if it's >= Particles_To_Use?
Can you post the part of codes around the line that call the function in question? I suspected in some way it got called more than once in ONE single game loop, unless that's what you intended to do.