Re: [code] [NEWBIE] Question about calling GET_CLASS(ch)

From: Andrew (object@ALPHALINK.COM.AU)
Date: 11/06/98


>do_score in act.informative.c The below is what I tried to use:
>  sprintf(buf, "Class: %d", GET_CLASS(ch));
>  if (GET_REMORT(ch) >= 0) {
>  sprintf(buf,  "   Dual: %d", GET_REMORT(ch));
> }
>
>Now I have no compiling problems, but when you type score now it displays
>a number instead of a class name.  I have this same problem when I call
>GET_NAME(ch) in a mudlog command, it just displays a number.  Can anyone
[snip]

Ok. A %d basically stands for an integer, not a string of characters. Also,
the GET_CLASS(ch) macro returns a number which corresponds to a player's class,
instead of returning the actual name of the class. That is why you get a number
instead of an actual string of characters. To work out which number corresponds
to which class, look at the defines in structs.h. This should fix it for you:

/* Start code here */
 sprintf(buf + strlen(buf), "Class: ");

 switch(GET_CLASS(ch)) {
 case CLASS_MAGIC_USER:
      sprintf(buf + strlen(buf), "Magic User\r\n");
      break;
 case CLASS_CLERIC:
      sprintf(buf + strlen(buf), "Cleric\r\n");
      break;
 case CLASS_THIEF:
      sprintf(buf + strlen(buf), "Thief\r\n");
      break;
 case CLASS_WARRIOR:
      sprintf(buf + strlen(buf), "Warrior\r\n");
      break;
 default:
      log("Invalid class parsed to do_score.");
      break;
}
/* End code */

That should fix your problem. Remember, whenever you use sprintf() you are
overwriting
whatever was in buf beforehand. To append to buf, use sprintf(buf +
strlen(buf), "Blah").
Just watch that with your remort thing. As with your GET_NAME(ch) macro,
make sure that
you use %s instead of %d, because GET_NAME(ch) actually refers to a string,
not an integer
like GET_CLASS(ch). If it still doesn't work, send me a copy of your
GET_NAME macro.

-- Andrew Ritchie.

| Andrew Ritchie, object@alphalink.com.au.


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



This archive was generated by hypermail 2b30 : 12/15/00 PST