Re: [NEWBIE] Circle Score Bug

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 11/13/00


Cam Peter wrote:
>
>   When I first got circle3.0 running under win98, i
> inherited 3 bugs, and 3 unrelated warnings...the
> warnings I still have (somewhat inconvenient, but not
> doing any real damage).

Fix the warnings, they're there for a reason.

> The second was with displaying the race
> on the score sheet as the original number instead of a
> word, which i took care of with an if statement.

There is an array of the race names somewhere, if you used Nashak's
snippet then it is pc_race_types.  You can easily get the name for
printing just by doing pc_race_types[race] where race is the variable
with the number of the race.

> The
> third bug has me absolutely stumped, and everyone else
> I've asked to look at it hits the same wall.

Post the relevent code so we can see exactly what is happening.

> Basically, the buffer behaves differently for score
> than for other commands...when i type it, it will
> display the last line of text shown as the first line
> of the score sheet, be it mob name/desc, room text,
> etc.  If I hit score a second or multiple times, it
> will cumulatively add score sheets (so the second
> time, i get 2 more score sheets for a total of three,
> etc...to the point that the mud crashes).

That problem comes from appending to the existing buffer rather than
overwriting it.  You are doing something like this...

sprintf(buf + strlen(buf), "Name: %s\r\n", name);
sprintf(buf + strlen(buf), "Age: %s\r\n", age);
sprintf(buf + strlen(buf), "Level: %s\r\n", level);
sprintf(buf + strlen(buf), "Score: %s\r\n", score);
send_to_char(buf, ch);

What you really need to do is overwrite the buffer for the first entry
and append for the balance as follows...

sprintf(buf, "Name: %s\r\n", name);
sprintf(buf + strlen(buf), "Age: %s\r\n", age);
sprintf(buf + strlen(buf), "Level: %s\r\n", level);
sprintf(buf + strlen(buf), "Score: %s\r\n", score);
send_to_char(buf, ch);

You might also see strcpy or strcat lines which do the same thing as
sprintf but for writing unformatted strings.  strcpy should be used for
the first line as it overwrites the buffer and strcat should be used for
the rest of the lines as it appends to the buffer.

>   The offending line is:   send_to_char(buf, ch)

All this line does is send the contents of buf to the player's screen
it's fine and is NOT the offending line.

> When I take the rest of the code for score out, that
> line still behaves in the above manner...

Chances are that you took out the first line of the original score
command that overwrote the buffer instead of appending to it, after that
you can take out as many lines as you want and it will still have that
problem.  The problem is with the line you took out, you need to change
the next line to overwrite instead of append.

>   My question is this...is there a command to force a
> buffer purge, and if so what is it?

Yes, but you shouldn't have to use it...

*buf = 0;

> If not, how can I
> fix this thing? Tearing my hair out here. :)
> Sorry if this question has been asked & answered
> before, and thanks in advance for yer help.

Regards, Peter


     +------------------------------------------------------------+
     | 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