On Sun, 3 Jun 2001, Jacob Farmer wrote: > Maybe I'm missing something obvious, but I can't figure out which function > returns the name/number of the victim of a player's battle. Is there a > function list I've missed or is it buried? There's no special function to do this. You can get a pointer to the character that a person is fighting using the FIGHTING macro. You can get the name of that character in the usual method (see the PERS macro), or any other information about that character that you may want to fetch. For instance, to send the name of the character vch is fighting to the character ch, you'd do sprintf(buf, "%s is fighting %s.", PERS(vch, ch), (FIGHTING(vch) ? PERS(FIGHTING(vch), ch) : "no-one")); send_to_char(buf, ch); or, similarly but without the trinary conditional operator, strcpy(buf, PERS(vch, ch)); if (FIGHTING(vch)) { strcat(buf, " is fighting "); strcat(buf, PERS(FIGHTING(vch), ch)); } else strcat(buf, " is fighting no-one."); send_to_char(buf, ch); How you choose to use the information gleaned from the character pointer is up to you. Remember, though, that if it's possible in your function for the character not to be fighting someone, you should check that the results of the FIGHTING macro are not NULL before you try to access them (otherwise you'll attempt to dereference a NULL pointer, which would cause a crash)[1]. I don't believe in simplifying examples to the point where they illustrate only the core of the idea and none of the subtleties a programmer will run into. -dak [1] If you don't think it's possible and this isn't production code, yet, use the assert() macro (see 'man assert' or your platform's equivalent online document) to make a programmatic statement of such a constraint. In this way, the error is clearly stated during your testing/development cycle for that given feature. -- +---------------------------------------------------------------+ | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html | +---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/05/01 PST