Re: Race/Class Snippet

From: Thomas Arp (t_arp@mail1.stofanet.dk)
Date: 11/09/00


From: "Lewis, Jason" <JLewis@birch.com>
> I am trying to install the race/class snippet and I am getting undeclared ch
> errors in this code.
>
> void display_classes(struct descriptor_data *d) {
>   int x;
>
>   send_to_char("Class selection menu - please choose a
> class\r\n---------------
> -----\r\n", d->character);
>   for (x = 0; x < NUM_CLASSES; x++)
--    if (class_ok_race[(int)GET_RACE(ch)][x]])
++    if (class_ok_race[(int)GET_RACE(d->character)][x]])
>       send_to_char(class_display[x], d->character);
>       send_to_char("\nClass: ", d->character);
> }
>
> I cannot figure out why I am getting this error as GET_RACE(ch) is the
> variable not ch, When I added races I added
>
> #define GET_RACE(ch)    ((ch)->player.race)
>

This MACRO is substituted everytime you compile, before the syntax
check. This means that the following is equivalent (though harder to
read and understand):

#define GET_RACE(XY123456789LSD) ((XY123456789LSD)-player.race)

in other words - in the code above you're trying to find the race
element of a given 'character-structure'. In this context this
'character-structure' isn't known as 'ch', but as a sub-element of the
'descriptor-structure' 'd'. Therefore you must use the
correct name - in this case 'd->character' to reference the
'character-structure'.

This is very basic C, and you might want to have a look at some tutorials (this one is on the university of Hull, whereever that is):
http://www.hull.ac.uk/Hull/CC_Web/docs/cnotes/contents.html

Hope my answer cleared things up for you.

Welcor


     +------------------------------------------------------------+
     | 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/11/01 PDT