Quake3World.com Forums
     Programming Discussion
        Value changing on it's own??


Post new topicReply to topic
Login | Profile | | FAQ | Search | IRC




Print view Previous topic | Next topic 
Topic Starter Topic: Value changing on it's own??

Grunt
Grunt
Joined: 25 Nov 2009
Posts: 65
PostPosted: 10-02-2011 10:08 PM           Profile Send private message  E-mail  Edit post Reply with quote


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




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 10-03-2011 09:33 AM           Profile Send private message  E-mail  Edit post Reply with quote


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.




Top
                 

Grunt
Grunt
Joined: 25 Nov 2009
Posts: 65
PostPosted: 10-03-2011 10:57 AM           Profile Send private message  E-mail  Edit post Reply with quote


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?




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 10-04-2011 05:56 AM           Profile Send private message  E-mail  Edit post Reply with quote


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

Quote:
And how can I check the other copy?

You can't, not directly anyway. The server and client may run on different machines.




Top
                 

Grunt
Grunt
Joined: 25 Nov 2009
Posts: 65
PostPosted: 10-05-2011 03:20 PM           Profile Send private message  E-mail  Edit post Reply with quote


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?




Top
                 

Mentor
Mentor
Joined: 12 Mar 2005
Posts: 3958
PostPosted: 10-06-2011 04:32 AM           Profile Send private message  E-mail  Edit post Reply with quote


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




Top
                 
Quake3World.com | Forum Index | Programming Discussion


Post new topic Reply to topic


cron
Quake3World.com
© ZeniMax. Zenimax, QUAKE III ARENA, Id Software and associated trademarks are trademarks of the ZeniMax group of companies. All rights reserved.
This is an unofficial fan website without any affiliation with or endorsement by ZeniMax.
All views and opinions expressed are those of the author.