18 Feb, 2011, Eithon wrote in the 1st comment:
Votes: 0
Hi all,

I am playing around with QuickMUD and what I am trying to do is to get autoexit to display exits with commas instead of spaces:

[Exits: north, south, west, down] instead of [Exits: north south west down]

In act_info.c:

if (fAuto)
{
strcat (buf, " ");
strcat (buf, dir_name[door]);
}

If I put a comma in there – strcat (buf, ", "); it gives me:

[Exits: , north, south, west, down]

And if I move it down to below strcat (buf, dir_name[door]); then it gives me:

[Exits: north, south, west, down, ]

I totally understand why it is coming out this way but can someone explain to me a way to have it format properly? I just want to figure out a way to have the last direction displayed without a comma but I don't know how to program the mud to do it. Thanks!
18 Feb, 2011, jurdendurden wrote in the 2nd comment:
Votes: 0
A pretty simple way around this problem can be done using your second method mentioned before, and checking to see when the door variable has reached 5 in the for loop in do_exits.

for (door = 0; door <= 5; door++)
{


If it is 5, then do not put the comma,

if (fAuto)
{
strcat (buf, " ");
strcat (buf, dir_name[door]);
if (door < 5)
strcat (buf, ",");
}
18 Feb, 2011, jurdendurden wrote in the 3rd comment:
Votes: 0
Actually this doesn't account for if it's the last exit but it's less than five, this won't work, hum let me think a second i'll get back to you ;)

Edit:

Ok here is the correct code :)


if (fAuto)
{
strcat (buf, " ");
strcat (buf, dir_name[door]);
if (door < 5)
{
if ((pexit = ch->in_room->exit[door+1]) != NULL) //checks to make sure the next exit is valid, otherwise we don't need the comma.
strcat (buf, ",");
}
}
18 Feb, 2011, Eithon wrote in the 4th comment:
Votes: 0
Jurdendurden,

Thank you for taking the time to help me out I really appreciate it. I implemented your code and it works perfectly in some rooms but not in others. This is what I am seeing when it doesn't work correctly (this is all running around the mud school arena, just to give you a frame of reference):

[Exits: east, south up]
[Exits: north south, west, up]
[Exits: north, east, south up]
[Exits: north, east, south, west, up,] (center of the arena)
[Exits: north, east up]
[Exits: north, east, south up]

It looks random to me, I can't see a pattern at all. I have to go back to work and don't have time at the moment to go in and try to see what is going on but I just thought I would post this in case you had any idea why it would be inconsistent. It's working find in some rooms:

[Exits: south, west, up]
[Exits: east, south, west, up]
[Exits: north, east, south, west, up], etc.

Thanks again for any light you can shed on this. I appreciate your time and I hope someday I can get all of this coding stuff figured out. It's fascinating!
18 Feb, 2011, Davion wrote in the 5th comment:
Votes: 0
Just add a comma before each iteration, except the first.
19 Feb, 2011, Scandum wrote in the 6th comment:
Votes: 0
Haven't tested this, but it should do the trick.

if (fAuto)
{
strcat (buf, " ");
strcat (buf, dir_name[door]);
strcat (buf, ",");
}

// outside the for loop

if (fAuto && buf[0])
{
buf[strlen(buf) - 1] = 0;
}
19 Feb, 2011, Eithon wrote in the 7th comment:
Votes: 0
That got it working Scandum. Thanks everyone for your help.
0.0/7