Value changing on it's own??
Posted: Mon Oct 03, 2011 6:08 am
I have a variable that is getting its value changed somehow and I don't understand it.
In bg_misc.c I have added a typedef like this:
Then in PM_Weapon() I want to check the value of the numClips of a weapon in order to take an action if the value is 0 (if they have no clips).
However, when I check the value of numClips from the type above, it gives unreliable data, sometimes telling the truth about how many clips there are, and other times saying 0 for some reason.
So I did a print statement:
(I even checked to make sure the value of WP_HE constant wasn't changing since the behaviour makes no sense)
What this prints out is:
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
and so on.
I put a debug print statement on every place in they code that sets or changes the value of any bg_weaponlist[].numClips[], and none of them are happening to change it to 0 or 2.
You can see that it has a pattern, where it is 0 once, then twice, then 3, 4, 5 times, then back to once.
This is baffling me. Anybody have any idea what's up with it? (I can post the SVN of all the code once I commit some recent stuff)
In bg_misc.c I have added a typedef like this:
Code: Select all
wpinfo_t bg_weaponlist[] ={
{ //WP_NONE, //0 Used for misc counts, rounds are for burst count.
"",
{0}, //weapMode
{0}, // numClips ammo that fits in the weapon
{0}, // rounds
""
},
{ //WP_KNIFE, //1
"icons/ammo/kbar",
{0}, //weapMode
{-1},
{5},
"models/weapons2/knife/"
},
{// WP_BERETTA, //2
"icons/ammo/beretta",
{0}, //weapMode
{0}, // numClips ammo that fits in the weapon
{0}, // rounds
"models/weapons2/beretta/"
},
... And so on for the rest of the weapons.
However, when I check the value of numClips from the type above, it gives unreliable data, sometimes telling the truth about how many clips there are, and other times saying 0 for some reason.
So I did a print statement:
Code: Select all
Com_Printf("HEVAL: %i HEs:%i Client: %i\n", WP_HE, bg_weaponlist[WP_HE].numClips[pm->ps->clientNum], pm->ps->clientNum );
What this prints out is:
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:0 Client: 0
HEVAL: 15 HEs:2 Client: 0
and so on.
I put a debug print statement on every place in they code that sets or changes the value of any bg_weaponlist[].numClips[], and none of them are happening to change it to 0 or 2.
You can see that it has a pattern, where it is 0 once, then twice, then 3, 4, 5 times, then back to once.
This is baffling me. Anybody have any idea what's up with it? (I can post the SVN of all the code once I commit some recent stuff)