Value changing on it's own??

Locked
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Value changing on it's own??

Post by bludshot »

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:

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.
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:

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 );
(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)
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Value changing on it's own??

Post by ^misantropia^ »

There's not enough information here to really tell (for instance, what does wpinfo_t look like?) but one thing that might be tripping you up is that PM_Weapon() runs on both the server and the client. Unless both sides of the connection meticulously update their copy of the numClips variable, you're going to see discrepancies.
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Value changing on it's own??

Post by bludshot »

Yeah but neither the client nor the server is updating the numclips in the above output example. It's changing from 2 to 0 and back (and in that increasing pattern of 0's) on it's own.

Here is wpinfo_t

typedef struct wpinfo_s {
char *ammoIcon;
int weapMode[MAX_CLIENTS];
int numClips[MAX_CLIENTS];
int rounds[MAX_CLIENTS];
char *modelPath;
} wpinfo_t;


You say the client and the server each have their own copy of numclips? When I do bg_weaponlist[WP_HE].numClips[pm->ps->clientNum] in PM_Weapon in bg_pmove.c, which copy does that refer to? And how can I check the other copy?
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Value changing on it's own??

Post by ^misantropia^ »

When I do bg_weaponlist[WP_HE].numClips[pm->ps->clientNum] in PM_Weapon in bg_pmove.c, which copy does that refer to?
Either and you can't really tell which. The pmove code is run by both server and client.
And how can I check the other copy?
You can't, not directly anyway. The server and client may run on different machines.
bludshot
Posts: 65
Joined: Thu Nov 26, 2009 6:14 am

Re: Value changing on it's own??

Post by bludshot »

So what does that mean? Does that mean we should move it out of BG and into G? Does it mean that what we were trying to use it for (and using it in that way) is just not something you should do?
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: Value changing on it's own??

Post by ^misantropia^ »

I assume numClips is a per-player thing? client->ps.stats[STAT_YOURSTAT] seems like the perfect place for it.
Locked