Re: a couple of questions.

From: Patrick Dughi (
Date: 02/04/00

Just to answer one unanswered question...

> >2.  How do I take input from a player?  (getchar() doesn't work.)
> I'm not the right person to answer this, the functions in comm.c are the
> ones that handle getting the inputs from players. Any input obtained will
> be parsed thru aliases to check for similarities. Then it is parsed by
> command_interpreter(). Anyway, giving further info on what you want to
> achieve might let others who knows better than me help you.

        The easiest way to get input, as indicated above, is to make a new
command, and parse the supplied variable "argument".  Circle even includes
some nice functions like one_argument() or half_chop() which makes parsing
a snap.  If you can find some examples out there, strtok isn't a bad thing
to use either (just make a backup of the string, strtok is destructive).

        Of course, if you're looking at getchar() and others, you probably
want prompted input - where the program waits for a response. From a
newbie standpoint, circlemud is not setup for prompted input at all; what
you'd find in most normal programs.

What is your name? ZiggyStarDust
Are you sure you want ZiggyStarDust as your name?

        That was not generated from simple[1] code.

        See, because unlike single-user applications, circle is a
multiuser application, and that means you cannot stop all processing each
time you want to wait till someone responds to a query or prompt.  Not
only that, but because you're actually parsing input from a network queue,
none of the standard *scanf(), getchar(), etc commands will work.

        What you should really do is to ask yourself "Do I really need a
prompted system."

        If the answer is still yes, you'll want to follow this procedure:


Many muds have an interactive prompt for remorting.  You use the command
"remort", and the mud prompts you back "Are you sure (Y/N)?".  In this
case, you're going to need one state;

                Waiting on a yes/no answer for the remort question.

Your 'remort' command (see ADDING THE COMMAND TO THE MUD)  can ask
the question, and then put you into this state. This is the state that
examines the input from the player - which is the next thing they type.
Just like any state, even playing, nothing is processed in the next state
until you type something out and hit return.  You'll also want to check if
it's a proper response (ie, something yes, or no, or an abbreviated
version of that, y or n), and perform some action (like asking again) if

If you ask multiple questions, with multiple decision paths, you won't
want to mess this step up or you cut your own throat later.

in structs.h, search down to the CON_x defines.  Go to the end, and add a
new state, incrementing the number by 1. To continue with our example, I
seach and find the last CON state to be
#define CON_DISCONNECT         17             /* In-game disconnection */

so, below this, I add
#define CON_REMORTYN           18             /* remort yes or no */

people always forget this. Open up constants.c and go to connected_types
definition, and add a new line at the bottom "Remort Y/N".  If you don't,
you can get screwy errors when you type 'users' and the state name is
accessed and does not exist because the array is too small.

open up interpreter.c and scan down to the nanny function.  Nearly
immediately it performs a switch on STATE(d).  Anywhere inside this
switch/case statement, you can add your new code; I usually start at the
bottom before the default case (which in stock code is case CON_DELCNF2).

  if(*arg == 'Y' || *arg == 'y') {
        /* do yes code here */
  } else if (*arg == 'N' || *arg == 'n') {
        /* return to game */
  } else {
        /* ask again */
    SEND_TO_Q("Please answer yes or no: ",d);

because actually writing and adding a command has been covered indepth,
I'm skipping it here.  However, make sure that before you exit the command
you do these two things:
        1. Give the character the prompt, like "Are you sure you want to
remort (y/n)? "
        2. set the STATE of the character to your new CON state. ex;

        That's it really, you're all done.

        Now, there are other ways to do it (reference Oasis), but I think
this is probably the easiest.


[1] Well it is actually simple code, but without decent understanding of
some basic concepts, it could be difficult, I guess.  It was the first
thing I looked at in circle code, though.

     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

This archive was generated by hypermail 2b30 : 04/10/01 PDT