Re: Autoexits problem

From: Kras Kresh (kras_kresh@hotmail.com)
Date: 09/08/02


>From: Ben Merton <ben@ADVENTEC.COM.AU>
>Subject: [CIRCLE] Autoexits problem
>Date: Sun, 8 Sep 2002 09:18:14 +1000
>Having some problems with autoexit, was hoping you guys could help. I'm
>running circle30bpl19, ascii pfiles, olc etc..
>
>The problem: just say for arguments sake that you have exits to the north,
>east and south... it will be displayed as:
>
>Exits: North, East, South.
>
>However if you have exits to the east and west, it will be displayed as:
>
>Exits: East West.
>
>The comma between east and west is gone... I have attached the related code
>below so you can see what I'm talking about..
>
>It is my belief that in the case of "east west" it is running sprintf(buf,
>"%s &c%s", buf, capdirs[door]); instead of sprintf(buf, "%s,", buf); but i
>cant see why this is occuring.
>
>Any assistance on this matter would be greatly appreciated, if there is any
>further information I can provide please contact me.
>
>Thanks, Ben
>
>-- SNIPPET --
>const char *capdirs[] = {
>   "North",
>   "East",
>   "South",
>   "West",
>   "Up",
>   "Down",
>   "\n"
>};
>
>void do_auto_exits(struct char_data * ch)
>{
>   int door;
>   bool flag = FALSE;
>
>   *buf = '\0';
>
>   for (door = 0; door < NUM_OF_DIRS; door++)
>       if (EXIT(ch, door) && EXIT(ch, door)->to_room != NOWHERE) {
>         if (flag) {
>                 sprintf(buf, "%s,", buf);
>                 }
>                 flag = TRUE;
>         if (IS_SET(EXIT(ch, door)->exit_info, EX_CLOSED)) {
>           sprintf(buf, "%s &c%s(Closed)", buf, capdirs[door]);
>         } else {
>           sprintf(buf, "%s &c%s", buf, capdirs[door]);
>         }
>       } else {
>           flag = FALSE;
>           }
>   sprintf(buf2, "&cExits:%s.&n\r\n", ((*buf) ? buf : "&c None"));
>
>-- END SNIPPET --

Your problem is simple. Your flag variable is causing problems and, is
actually, quite useless. Here, I'll rewrite your code:

void do_auto_exits(struct char_data * ch)
{
   int door;

   *buf = '\0';

   for (door = 0; door < NUM_OF_DIRS; door++)
     if (EXIT(ch, door) && EXIT(ch, door)->to_room != NOWHERE) {
       if (IS_SET(EXIT(ch, door)->exit_info, EX_CLOSED))
         sprintf(buf + strlen(buf), " %s(Closed),", capdirs[door]);
       else
         sprintf(buf + strlen(buf), " %s,", capdirs[door]);
     }
   sprintf(buf2, "&cExits:%s.&n\r\n", ((*buf) ? buf : " None"));

---- End Snippet ----

How clean does that look? Your color code in there is pointless as well.
Just have it in there at the last line. Shortens the buffer a bit too.

_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT