while loop not working

Posted By: Dooley

while loop not working - 12/07/16 22:46

I'm wondering if maybe my script is just too long to run properly, because I am getting some strange errors.

Quote:
while(1)
{
if(message_mship < 101)
{
toggle(mship_approach_pan,SHOW);
message_mship += 10;
}
else
{
message_mship = 0;
reset(mship_approach_pan,SHOW);
return;
}

wait(-.25);
}


This while loop gets stuck with the variable "message_mship" set at 11. It should keep looping until it eventually reaches 101, right? It worked in another function for a different flashing panel which is exactly pretty much the same function. I'm wondering if maybe my game's script is just too long and it's somehow forgetting to run through this particular loop.

Is that possible? Other loops in the same .c file seem to work fine though.

I've tried making the wait (1) instead of (-.25) but I get the same results. I've looked for any external function that might be resetting "message_mship" to 1, but can't find any. I've also tried using a different variable, just in case, but that doesn't work either...
Posted By: Dooley

Re: while loop not working - 12/07/16 22:49

I've also rewritten the loop like this...
Quote:

while(message_mship < 101)
{
toggle(mship_approach_pan,SHOW);
message_mship += 10;
wait(-.25);
}

message_mship = 0;
reset(mship_approach_pan,SHOW);
Posted By: Dooley

Re: while loop not working - 12/08/16 03:59

I figured it out ...

The function that called the function with the loop ends before the loop finishes, and that's why it gets stuck.

I'm pretty sure I encountered this before, and did not realize it until I found the cause.
© 2024 lite-C Forums