Re: Command_Interpreter

From: Daniel A. Koepke (
Date: 01/31/01

On Wed, 31 Jan 2001, Luke Waite wrote:

>   else if (cmd_info[cmd].command != 'charunlock\n' && GET_LOCK(ch) != 0
> && !IS_NPC(ch)) {
>     send_to_char("Sorry, character is locked. Type unlock, and the
> password you\r\n", ch);
>     send_to_char("entered when you locked.\r\n", ch);

No, no, no, no, no.  Two things about C: string literals are in double
quotes, not single quotes (character literals are in single quotes) so
'charunlock\n' is bad syntax, you want "charunlock\n" (but, not really,
I'll explain in a second); you're comparing the address of two pointers
instead of the contents of two strings, you want

  else if (str_cmp(cmd_info[cmd].command, "charunlock\n") && ...

(but, not really, I'll explain in a second).

The problems with your approach from CircleMUD's side: you want your
!IS_NPC(ch) check before the GET_LOCK(ch) check since it's player-specific
data.  In fact, you probably should put !IS_NPC(ch) first in the if and
GET_LOCK(ch) next.  Also, command names in the cmd_info table shouldn't
have newlines in them.  So you want "charunlock" not "charunlock\n".  If
you put "charunlock\n" in the table no-one would ever be able to use the
command because they can't put a newline after the command but before the

So, you should end up with something like:

  else if (!IS_NPC(ch) && GET_LOCK(ch) &&
           str_cmp(cmd_info[cmd].command, "charunlock")) {
    /* . . . */
  } else if . . .

Note that you *DO* want str_cmp() and *DO NOT* want !str_cmp().  As
mentioned several times before, str_cmp() does a lexicographical
comparison, not a boolean (true/false) comparison.  It returns zero (0) if
the strings *DO* match, non-zero if the strings *DO NOT* match.

Check the archives or a good book on C for more information on
lexicographical comparisons.


   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/03/01 PST