Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Question about CHAR_DATA *victim

Question about CHAR_DATA *victim

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by MattJ820   (32 posts)  Bio
Date Sun 10 May 2015 03:50 AM (UTC)

Amended on Sun 10 May 2015 04:49 AM (UTC) by MattJ820

Message
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;
};
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 10 May 2015 04:28 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by MattJ820   (32 posts)  Bio
Date Reply #2 on Sun 10 May 2015 04:51 AM (UTC)

Amended on Sun 10 May 2015 04:52 AM (UTC) by MattJ820

Message
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
Top

Posted by MattJ820   (32 posts)  Bio
Date Reply #3 on Sun 10 May 2015 04:55 AM (UTC)
Message
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;
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #4 on Sun 10 May 2015 05:33 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #5 on Sun 10 May 2015 05:34 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #6 on Sun 10 May 2015 05:37 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by MattJ820   (32 posts)  Bio
Date Reply #7 on Mon 11 May 2015 11:04 PM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,169 posts)  Bio   Forum Administrator
Date Reply #8 on Tue 12 May 2015 02:46 AM (UTC)

Amended on Tue 12 May 2015 08:08 PM (UTC) by Nick Gammon

Message
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
  }

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by MattJ820   (32 posts)  Bio
Date Reply #9 on Tue 12 May 2015 08:55 PM (UTC)
Message
Ya, that structure is what I was thinking of.

Thank you Nick
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


29,184 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.