Question about CHAR_DATA *victim

Posted by MattJ820 on Sun 10 May 2015 03:50 AM — 10 posts, 31,472 views.

#0
Hi,

I was curious about why victim is referenced in functions like CHAR_DATA *victim when victim is not actually in the char_data struct?

It's here


struct  fellow_data
{

    char *		victim;
    char *		knownas;
    FELLOW_DATA *	next;
    FELLOW_DATA *	prev;
};
Amended on Sun 10 May 2015 04:49 AM by MattJ820
Australia Forum Administrator #1
The char type is a generic character. So char* is just a pointer to a string of bytes. It is nothing to do with CHAR_DATA.

I'm guessing from what you posted it would be a string containing the victim's name.
#2
Why doesn't victim appear in the CHAR_DATA struct?

It's in a lot of different functions that way?

For example
void do_checkprints(CHAR_DATA *ch, char *argument )
{
bool checkdata;
bool checkcomm;
OBJ_DATA *obj;
CHAR_DATA *victim; <-----------
}

But the struct char_data in mud.h doesn't have victim in it
Amended on Sun 10 May 2015 04:52 AM by MattJ820
#3
The reason why I asked is I stumbled onto it trying to figure out why I can't get this to work. Object killer is the name of the player that killed someone (created the corpse). I want to assign that player to victim and then access that characters skill list to check if they have learned professional. If they know it, the prints will not be visible.

}
victim = obj->killer;
if(victim->pcdata->learned[gsn_professional]
send_to_char("It appears as if the prints have been wiped clean on this body.\n\r", ch)
else
{

incompatible pointer types assigning to 'CHAR_DATA *' (aka 'struct char_data *') from 'char *' [-Wincompatible-pointer-types]
victim = obj->killer;
Australia Forum Administrator #4
Quote:

CHAR_DATA *victim; <-----------


But the struct char_data in mud.h doesn't have victim in it


Neither it should have. CHAR_DATA is a type. That line creates a pointer to an instance of that type. It happens to be called "victim".

You could do this:


CHAR_DATA *foo;


That doesn't mean "foo" has to be inside CHAR_DATA.
Australia Forum Administrator #5
Quote:

The reason why I asked is I stumbled onto it trying to figure out why I can't get this to work.


You probably have to call a function to look up someone by name and return a CHAR_DATA type.
Australia Forum Administrator #6
MattJ820 said:

Why doesn't victim appear in the CHAR_DATA struct?


If I have a book called "Accidental Empires" that is the name of the book. It doesn't mean that the words "Accidental Empires" has to be inside the book.

In your case, MattJ820, if we looked inside you, would we find MattJ820? I doubt it. That's just your name.
#7
Oh I see, I thought that CHAR_DATA represented the structure and *victim was an item inside that structure. That's why I was confused on how it can be when it wasn't listed inside mud.h as existing in that structure. This is a hard thing to learn by reading and trial and error..maybe I should take some classes.
Australia Forum Administrator #8
Just do some basic C tutorials. You might be thinking of this. Given that CHAR_DATA looks like this:


struct char_data
{
...
   short timer;
   short wait;
   short hit;
   short max_hit;
   short mana;
   short max_mana;
...


Then if you use it, you can get to things inside it, like this:


char_data * foo;   // <-- pointer to an instance of char_data

...

if (foo->mana >= 100)
  {
  // do something
  }
Amended on Tue 12 May 2015 08:08 PM by Nick Gammon
#9
Ya, that structure is what I was thinking of.

Thank you Nick