variable changing value when not referenced!
Displaying 1-5 of 5 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Technetium

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.

Posted on 2004-03-20 05:58:22

anonymous

for(loop[1]=dirtheight;loop[1] LT 480;loop[1]++)
{
dirt[loop[0]][480-loop[1]]=0;
}

If it's possible that dirtheight == 0, you are accessing dirt[*][480]

El Desconocido

Posted on 2004-03-20 19:04:23

Overkill

How about the line:


GenBG(1);


What does it do? Just curious.

ALSO:
--------------------
Since I think people will find this helpful:

HOW TO PLACE CERTAIN SYMBOLS IN HTML:
&lt; and &gt; give you < and >
&amp; gives you &
&and; gives you ∧
If a symbol doesn't show up, fire up Frontpage Express, type the symbol in there, and click View >> HTML.

Posted on 2004-03-20 20:53:33 (last edited on 2004-03-20 21:08:04)

Technetium

If it's possible that dirtheight == 0, you are accessing dirt[*][480]
I think that was the problem. I rewrote the whole thing a different way that I thought would achieve the same effect, and it seems to work fine now.

Still, trying to reference an out-of-index array element normally crashes the game rather than altering unrelated variables.

Thanks for the help.

Posted on 2004-03-21 00:55:12

vecna

traditionally I try to catch out of bound array accesses (well, theres no try about it, I do, but it seems to be slightly broken ^_^), however, when it doesnt work, it would only crash if the offset was way off, or at the end of the allocated variable space, otherwise, its just like any other language, it will overwrite other variables stored nearby in memory.

Posted on 2004-03-21 01:53:44


Displaying 1-5 of 5 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.