Re: Structures for player data and variables within

From: Deja Augustine (PraetorXI@aol.com)
Date: 03/20/00


As far as I can tell, you are correct...

Basically what we have here is a case of nested structures...

Here's the code in question:

(ch)->player.level

Since structures can be accessed by one of two operators (-> and .) basically what that code is doing is telling the program that you want to use, in some way, the data stored in the "level" variable stored in the char_player_data structure declared with the name "player" which is, itself, stored in the char_data structure declared with the name "ch".

Also, in reference to the macro question that sparked this whole thing off, when you use a macro, it's similar to using a function:

in the line:
GET_LEVEL(character_structure) = 5;

your passing the char_data structure called "character_structure" to the macro so that "character_structure" replaces the "ch" in the following line:

#define GET_LEVEL(ch) ((ch)->player.level)

So that mess above becomes:

#define GET_LEVEL(character_structure) ((character_structure)->player.level)

which then replaces the macro so you get:

(character_structure)->player.level = 5;

in the original call.


I hope that did more than add to the confusion.
-Praetor

In a message dated Mon, 20 Mar 2000 12:46:04 PM Eastern Standard Time, "Minturn.Del.PRC.Oceana" <Del@PRCOceana.Corona.Navy.Mil> writes:

> The recent question on the understanding of (ch)->player.level
> was directed to me personally. However I was not 100 percent sure
> of my answer. (mostly terminology)
>
> The basic question was why (ch)->player.level was just that, instead of
> (ch)->level.
>
> I had never researched it before, and myself being inexperienced with
> structures, I followed the code through for this type of answer.
>
> Can the more experienced put the right labels on my answer or better
> explanation? or atleast let me know if my understanding is correct.
>
> structs.h:
>
> struct char_player_data {
> <snip>
>    byte level;         /* PC / NPC's level                     */
> <snip>
>
> struct char_data {
> <snip>
>    struct char_player_data player;       /* Normal data                   */
> <snip>
>
>
> NOTE: the variable name player.
>
> It was hiding in there and if I read it right..
>
> ch = char_data structure (in this scenerio)
> player = char_player_data structure
> level = the finial variable in the structure mess!
>
>
>      +------------------------------------------------------------+
>      | Ensure that you have read the CircleMUD Mailing List FAQ:  |
>      |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
>      +------------------------------------------------------------+


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/10/01 PDT