Server Help

ASSS Questions - Random values from PDATA

Anonymous - Wed Feb 16, 2011 6:39 am
Post subject: Random values from PDATA
Hey,

I have this weird problem:
I load data onto a pdata struct
after it loads the output is this, which is correct:
Warbird: Level - 1, EXP - 200
Javelin: Level - 0, EXP - 0
Spider: Level - 0, EXP - 0
Leviathan: Level - 0, EXP - 0
Terrier: Level - 0, EXP - 0
Weasel: Level - 0, EXP - 0
Lancaster: Level - 0, EXP - 0
Shark: Level - 0, EXP - 0

Then I want to confirm the output by displaying it once more using a command ?mystats:
snake> ?mystats
Level - 1
Level - 0
Level - 15
Level - 1
Level - 0
Level - 0
Level - 0
Level - 0
then i wait a while(10 secs), doing nothing in the zone:
snake> ?mystats
Level - 1
Level - 0
Level - 77
Level - 97
Level - 11
Level - 1
Level - 0
Level - 0

and once more:
snake> ?mystats
Level - 1
Level - 0
Level - 77
Level - 164
Level - 36
Level - 1
Level - 0
Level - 0


the values seem to increase for some reason....

any idea why?

the struct is typedef struct MyPlayerData
{
int level[8];
int exp[8];
int oldship;
} MyPlayerData;


and i access it with:

Code: Show/Hide

local void ShowStats(const char *command, const char *params, Player *p, const Target *target)
{
   MyPlayerData* pdata = PPDATA(p, playerKey);
   if (pdata)
   {
      int i;
      for (i=0;i<8;i++)
      {
         //if (pdata->level[i] > (start_level[i]))
         chat->SendArenaMessage(p->arena,"Level - %i", pdata->level[i]);
      }
   }
   
}



thanks
Dr Brain - Wed Feb 16, 2011 7:07 am
Post subject:
Do you allocate the memory with amalloc? Make sure you use the size of the struct and not the size of a pointer to the struct.

Your access code looks fine to me, so lets see the init code.
Anonymous - Wed Feb 16, 2011 7:34 am
Post subject:
this is embarrassing, but apparently while i was cleaning up my code, i had accidently deleted


playerKey = pd->AllocatePlayerData(sizeof(MyPlayerData));

thanks anyhow lol
Arnk Kilo Dylie - Wed Feb 16, 2011 4:41 pm
Post subject:
If you learn ACE, you can save yourself worrying about a lot of the init/deinit details like that. </shamelessplug> icon_wink.gif
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group