I have a variable that changes value unexplainably. I ran a search for this variable in Textpad and it is only written to towards the beginning of the game. It is read from many times later on, and somehow it is getting changed.
By using log() I have been able to narrow down the location where it changes value. Unfortunately, it appears to be changing value at the line where a for-loop begins. I put a log() statement right before the for-loop, and it gives me a value of 2 (the correct value). I put another log statement as the first line within the for-loop, and it gives me a value of 1. The variable is not mentioned as one of the conditions of the for-loop, and the conditions of the for-loop do not make use of any functions which return values. I have also not used any hooktimer or hookretrace stuff which would allow any code to run at the same time that this is going on. I really can't understand this problem. I'll paste in the whole function. I left in comments explaining where the variable changes.
The variable in question "currentBG" only changes value in that for-loop the last time the outer for-loop is being run through, meaning when loop[0] = 639.
Note: I replaced the greater-than and less-than signs with "GT" and "LT"because I don't know the html codes for those characters.
--------------------------------------------------
void settledirt()
{
int dirtheight;
for(loop[0]=0;loop[0] LT 640;loop[0]++)
{
dirtheight=0;
for(loop[1]=0;loop[1] LT 480;loop[1]++)
{
if(dirt[loop[0]][loop[1]]==1)
{
dirtheight++;
}
}
if(loop[0]==639)
{
log(str(currentBG)); //equals 2
}
for(loop[1]=0;loop[1] LT dirtheight;loop[1]++)
{
if(loop[0]==639 && loop[1]==0)
{
log(str(currentBG)); // equals 1
}
dirt[loop[0]][480-loop[1]]=1;
}
for(loop[1]=dirtheight;loop[1] LT 480;loop[1]++)
{
dirt[loop[0]][480-loop[1]]=0;
}
}
falldirt=0;
GenBG(1);
}
-----------------------------------------------------------------
I hope you can follow the code, it's adding extra line breaks for some reason.