Re: Source for Scoreboard

From: Sean Daley (sdaley@bbnplanet.com)
Date: 03/04/99


>>  for (d = descriptor_list; d; d = d->next) {
>>
>> if (str_cmp("paintball", buf)) {
>>   if (PRF_FLAGGED(d->character, PRF_PAINTBALL))
>>     sprintf(scorebuf,"%s %15s Individual %d      None"
>>     ,scorebuf,GET_NAME(d->character),GET_SCORE(d->character));
>>     }
>>
>>  else if (str_cmp("lasertag", buf)) {
>>   if (PRF_FLAGGED(d->character, PRF_LASERTAG))
>>     sprintf(scorebuf,"%s %15s Individual %d      None"
>>     ,scorebuf,GET_NAME(d->character),GET_SCORE(d->character));
>>     }
>>}
>
>One of these should always be true, at least, especially because you're
>using str_cmp() wrong.  Here's something I would do.
>
>const char *scoreboard_games[] =
>  "paintball",
>  "lasertag",
>  "\n"
>};

Actually there is nothing "wrong" with trying to do it with if statements
and str_cmp or strcmp for that matter.  Nothing wrong with the way you
suggested either, to each his/her/its own.

One of the problems with the above original code is the following.

Let's assume buf = "paintball"

if (str_cmp("paintball", buf)) { ...
This shows a lack of understanding of the str_cmp function.
As everyone who is coding for a mud should know, when using
str_cmp or strcmp, if str_cmp considers the two arguments the
same, then str_cmp will return 0 and the if will evaluate as
if (0) and the code he wants executed for paintball will never
be done.  It will then drop to the lasertag part.
else if (str_cmp("lasertag", buf)) {...
Here the two aren't equal so it returns a non-zero value and
actually does the lasertag stuff.

You probably want to do something like the following:
if (!str_cmp("paintball", buf))

The same goes for the lasertag one and any others you may
add in the future.

Of course, I don't really know what the original message was,
so I'm not sure if this will answer what the original problem
was.  I don't really know how buf is getting set up, etc.

Oh well, hope this helps anyway.

Sean


     +------------------------------------------------------------+
     | 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 : 12/15/00 PST