Server Help

ASSS Questions - PlayerData

Anonymous - Mon Jul 02, 2007 9:54 am
Post subject: PlayerData
I have module which has player data which needs initialization.

So I am using PA_ENTERGAME in the PlayerAction Callback to initialize the variable.

However this seems to crash asss

Code: Show/Hide

local void PlayerAction (Player *p, int action, Arena *arena)
{
   if (action == PA_ENTERGAME) //Also crashes with PA_ENTERARENA
   {
      playerData* pdata = PPDATA(p, playerKey); //No crash if commented out
      pdata->blah = -1;
   }
}

The first time I enter nothing happens, but if I gotp a subarena, then come back to the public arena where it is attached, asss crashes.

There is nothing on the console and asss isn't entirely crashed (some things still work), I just get a windows error message box telling me a read/write operation on the memory failed.


Is it correct to initialize player data this way? Do I need to use a different callback?
Animate Dreams - Mon Jul 02, 2007 3:29 pm
Post subject:
I think it's perfectly fine to do it inside of PlayerAction, and both PA_ENTERGAME and PA_ENTERARENA. The only thing I can think of... you sure blah is a valid variable inside playerData? Also, I'd double-check your caps, to make sure they're all the same. It'd be nice to see your declaration of the playerData struct, too.
JoWie - Mon Jul 02, 2007 4:16 pm
Post subject:
here is the entire source
Animate Dreams - Mon Jul 02, 2007 4:40 pm
Post subject:
Well, since all you're doing is freeing your playerdata if it fails to load(line 75 for example), you really have no way of knowing if it ever loaded successfully. Also, why do you initialize your playerKey to be -1? I don't think you have to do that. Though, I'm pretty sure it gets written over, so that shouldn't be the problem. Anyway, you could rewrite the part, under MM_LOAD, to send an error message to the console when it wasn't allocating data properly, that way you'd know if the error was in allocation.

I also don't understand the oldship = -1. I didn't know that was valid, either. It might be, though. I'm no expert. I suppose you could try messing with it anyway. I'd try it myself, but I'm at work, and I forgot my IP so I can't ssh to my computer at home. icon_sad.gif
JoWie - Mon Jul 02, 2007 4:53 pm
Post subject:
If the player data fails to load, MM_FAIL is returned which means the module fails to load (and you get a message on your console IIRC). MM_ATTACH is then never called, this means the PlayerAction callback never gets registered.

Ship 0 is warbird
I set oldShip to -1 so the LVZ gets shown if your first ship is a warbird.

The reason why I use oldShip is to turn of the old LVZ object
tcsoccerman - Tue Jul 03, 2007 10:19 am
Post subject:
Code: Show/Hide
local void PlayerAction (Player *p, int action, Arena *arena)
{
   if (p->action == PA_ENTERGAME)
   {
      playerData* pdata = PPDATA(p, playerKey); //No crash if commented out
      pdata->blah = -1;
   }
}

my attempt. just added "p->" in if statement
Animate Dreams - Tue Jul 03, 2007 4:59 pm
Post subject:
Um, action is an int passed in by the function, PlayerAction, as you can see on line 1.
tcsoccerman - Tue Jul 03, 2007 5:02 pm
Post subject:
which means look in players.h or something to see what that is equal to in #'s.
Cyan~Fire - Tue Jul 03, 2007 5:27 pm
Post subject:
What? Animate is right, that's definitely not going to fix anything. (It will break things, instead.)
tcsoccerman - Tue Jul 03, 2007 5:39 pm
Post subject:
nvm. i thought it would be similiar to mapdata, for example NO_TILE = 0, TILE_END = 1. and so on. i guess they're not the same.
Animate Dreams - Tue Jul 03, 2007 5:59 pm
Post subject:
My point is, action isn't a variable in the Player struct. It is passed in, right there, in that function, on line 1. So simply checking "action" is correct. Even if there was a variable named action in the player struct, I'm pretty sure you'd still be expected to use the action passed in by the function. After all, that's why it's passed in.
JoWie - Tue Jul 03, 2007 6:28 pm
Post subject:
Getting back to the original problem, any idea why it crashes when requesting per player data in PA_ENTERGAME?
Smong - Wed Jul 04, 2007 11:41 am
Post subject:
I looked at it and couldn't get it to crash under linux. Under windows I can't tell if it's this module or another one causing it (I have so much custom stuff loaded). Maybe it's conflicting with another module? Although I would have thought pdkey would equal -1 if asss couldn't allocate space for it.
JoWie - Mon Jul 16, 2007 9:41 am
Post subject:
I have solved it. I added a few checks, I am not 100% sure which check solved the crashing but here is what I changed:

Code: Show/Hide

local void PlayerAction (Player *p, int action, Arena *arena)
{
   if (!p->arena || p->arena != arena || playerKey == -1) return; //Added, kind of an overkill

   if (action == PA_ENTERGAME)   {
      playerData* pdata = PPDATA(p, playerKey);
      if (!pdata) return; //Added
      pdata->oldShip = -1;
   }
}


I think the culprit was p->arena, since that can be NULL (see player.h)
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group