1999Q2/
<!-- MHonArc v2.4.4 -->
<!--X-Subject: Re: [MUD&#45;Dev] i got's a question for yall on the best way to do something.. -->
<!--X-From-R13: "Xvz Qynex" <fbzrjurerNfcevag.pn> -->
<!--X-Date: Thu, 17 Jun 1999 14:48:01 &#45;0700 -->
<!--X-Message-Id: 006701beb8f1$4e81a160$1161a8c0#phonelabs,com -->
<!--X-Content-Type: text/plain -->
<!--X-Reference: c985a846.2499f5c6#aol,com -->
<!--X-Head-End-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>MUD-Dev message, Re: [MUD-Dev] i got's a question for yall on the best way to d</title>
<!-- meta name="robots" content="noindex,nofollow" -->
<link rev="made" href="mailto:somewhere#sprint,ca">
</head>
<body background="/backgrounds/paperback.gif" bgcolor="#ffffff"
      text="#000000" link="#0000FF" alink="#FF0000" vlink="#006000">

  <font size="+4" color="#804040">
    <strong><em>MUD-Dev<br>mailing list archive</em></strong>
  </font>
      
<br>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
<br clear=all><hr>
<!--X-Body-Begin-->
<!--X-User-Header-->
<!--X-User-Header-End-->
<!--X-TopPNI-->

Date:&nbsp;
[&nbsp;<a href="msg00837.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00839.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Thread:&nbsp;
[&nbsp;<a href="msg00834.html">Previous</a>
&nbsp;|&nbsp;<a href="msg00840.html">Next</a>
&nbsp;]
&nbsp;&nbsp;&nbsp;&nbsp;
Index:&nbsp;
[&nbsp;<A HREF="author.html#00838">Author</A>
&nbsp;|&nbsp;<A HREF="#00838">Date</A>
&nbsp;|&nbsp;<A HREF="thread.html#00838">Thread</A>
&nbsp;]

<!--X-TopPNI-End-->
<!--X-MsgBody-->
<!--X-Subject-Header-Begin-->
<H1>Re: [MUD-Dev] i got's a question for yall on the best way to do something..</H1>
<HR>
<!--X-Subject-Header-End-->
<!--X-Head-of-Message-->
<UL>
<LI><em>To</em>: &lt;<A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A>&gt;</LI>
<LI><em>Subject</em>: Re: [MUD-Dev] i got's a question for yall on the best way to do something..</LI>
<LI><em>From</em>: "Jim Clark" &lt;<A HREF="mailto:somewhere#sprint,ca">somewhere#sprint,ca</A>&gt;</LI>
<LI><em>Date</em>: Thu, 17 Jun 1999 14:43:29 -0400</LI>
<LI><em>Reply-To</em>: <A HREF="mailto:mud-dev#kanga,nu">mud-dev#kanga,nu</A></LI>
<LI><em>Sender</em>: <A HREF="mailto:mud-dev-admin#kanga,nu">mud-dev-admin#kanga,nu</A></LI>
</UL>
<!--X-Head-of-Message-End-->
<!--X-Head-Body-Sep-Begin-->
<HR>
<!--X-Head-Body-Sep-End-->
<!--X-Body-of-Message-->
<PRE>
You still want a state machine, but that horrible 1000 line switch is not
a good way to implement a state machine. The first step to make a decent
deterministic state machine would be to write down a list of states:

connect -&gt; login -&gt; new char -&gt; new char passwd -&gt; ect..
             |
             -----&gt; old char -&gt; get old char password -&gt; playing
                                       |
                                       --&gt; bad password

After you have a decent map of state transitions, you can get down
to the implementation. (It's been a few years since I did any large
state machines so bear with me)

First create a nice list of constants, one for each state.
const int STATE_CONNECT = 0;
const int STATE_LOGIN = 1;
const int STATE_OLD_CHAR = 2;
const int STATE_NEW_CHAR = 3;
ect..

const int MAX_STATE = 20; // Or whatever

Then make a large table which maps old state vs. next state.
With function pointers


const STATEHANDER STATE_TABLE[MAX_STATE][MAX_STATE] =
{
//         Next State (the one we are moving to)
//               Connect  Login   Old Char  NewChar
/* Connect  */ { NULL,    Login,  NULL,     NULL    },
/* Login    */ { NULL,    NULL,   OldChar,  NewChar },
/* Old Char */ { NULL,    NULL,   NULL,     NULL    },
/* New Char */ { NULL,    NULL,   NULL,     NULL    }
};

This table defines the links between states, as well as where to go next.
Some function such as this will handle that.

void HandleState( Ch* pCh, const String&amp; strIn )
{
    // I can't rember if this is the right member function
    // syntax, and I'm to lazy to dig it up
    // And you should of course check for NULL's
    pCh-&gt;*( STATE_TABLE[pCh-&gt;m_nLastState][pCh-&gt;m_nCurrState] )( strIn );
}

And lastly an example of a STATEHANDLER, in psuado code

void Ch::Login( const String&amp; strIn )
{
    if( strIn IS AN old player )


        m_nLastState = m_nCurrState;
        m_nCurrState = STATE_OLD_CHAR;
        Out( "some message about entering a password" );
    }
    else
    {
        m_nLastState = m_nCurrState;
        m_nCurrState = STATE_NEW_CHAR;
        Out( "some message about new characters and some instructions about
entering a new password" );
    }
}

-Jim

----- Original Message -----
From: &lt;PartyG2816#aol,com&gt;
To: &lt;mud-dev#kanga,nu&gt;
Sent: Thursday, June 17, 1999 2:55 AM
Subject: [MUD-Dev] i got's a question for yall on the best way to do
something..


&gt; Ok, any of yall familiar with the ROM code base? Tis a text based mud.
Well,
&gt; they handle character creation via this big, ugly, confusing state
machine..
&gt; Hard as hell to find stuff in, and just a bitch to look at.   Well, I've
&gt; finally got around to starting my own mud in C++, tired of modifying ROM's
&gt; and Oblivions yadda yadda, and gotten to the point where I need to figure
out
&gt; a way to handle this.. The only way I know of doing it is via a big ugly
&gt; state machine like ROM and most of the other's that I've seen use.. Mainly
&gt; the Diku derivatives.  What are some other ways a person might go about
doing
&gt; it? Any input would be greatly appreciated.. And if you need more info on
&gt; what I'm talking about, just ask and I'll try to supply ;-)
&gt;
&gt; Thanx,
&gt; JD





_______________________________________________
MUD-Dev maillist  -  MUD-Dev#kanga,nu
<A  HREF="http://www.kanga.nu/lists/listinfo/mud-dev">http://www.kanga.nu/lists/listinfo/mud-dev</A>


</PRE>

<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<HR>
<!--X-Follow-Ups-End-->
<!--X-References-->
<UL><LI><STRONG>References</STRONG>:
<UL>
<LI><STRONG><A NAME="00834" HREF="msg00834.html">[MUD-Dev] i got's a question for yall on the best way to do something..</A></STRONG>
<UL><LI><EM>From:</EM> PartyG2816#aol,com</LI></UL></LI>
</UL></LI></UL>
<!--X-References-End-->
<!--X-BotPNI-->
<UL>
<LI>Prev by Date:
<STRONG><A HREF="msg00837.html">RE: [MUD-Dev] Different approaches?</A></STRONG>
</LI>
<LI>Next by Date:
<STRONG><A HREF="msg00839.html">Re: [MUD-Dev] Properties of computer languages</A></STRONG>
</LI>
<LI>Prev by thread:
<STRONG><A HREF="msg00834.html">[MUD-Dev] i got's a question for yall on the best way to do something..</A></STRONG>
</LI>
<LI>Next by thread:
<STRONG><A HREF="msg00840.html">Re: [MUD-Dev] i got's a question for yall on the best way to do something..</A></STRONG>
</LI>
<LI>Index(es):
<UL>
<LI><A HREF="index.html#00838"><STRONG>Date</STRONG></A></LI>
<LI><A HREF="thread.html#00838"><STRONG>Thread</STRONG></A></LI>
</UL>
</LI>
</UL>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
<ul><li>Thread context:
<BLOCKQUOTE><UL>
<LI><STRONG>Re: [MUD-Dev] i got's a question for yall on the best way to dosomething..</STRONG>, <EM>(continued)</EM>
<ul compact>
<LI><strong><A NAME="00844" HREF="msg00844.html">Re: [MUD-Dev] i got's a question for yall on the best way to dosomething..</A></strong>, 
PartyG2816 <a href="mailto:PartyG2816#aol,com">PartyG2816#aol,com</a>, Thu 17 Jun 1999, 23:36 GMT
</LI>
</ul>
</LI>
<LI><strong><A NAME="00841" HREF="msg00841.html">[MUD-Dev] Game Design [Simulation]</A></strong>, 
Justin Lockshaw <a href="mailto:JustinL#HQ,Autoweb.com">JustinL#HQ,Autoweb.com</a>, Thu 17 Jun 1999, 21:48 GMT
<LI><strong><A NAME="00837" HREF="msg00837.html">RE: [MUD-Dev] Different approaches?</A></strong>, 
Koster, Raph <a href="mailto:rkoster#origin,ea.com">rkoster#origin,ea.com</a>, Thu 17 Jun 1999, 18:31 GMT
<LI><strong><A NAME="00834" HREF="msg00834.html">[MUD-Dev] i got's a question for yall on the best way to do something..</A></strong>, 
PartyG2816 <a href="mailto:PartyG2816#aol,com">PartyG2816#aol,com</a>, Thu 17 Jun 1999, 15:38 GMT
<UL>
<LI><strong><A NAME="00838" HREF="msg00838.html">Re: [MUD-Dev] i got's a question for yall on the best way to do something..</A></strong>, 
Jim Clark <a href="mailto:somewhere#sprint,ca">somewhere#sprint,ca</a>, Thu 17 Jun 1999, 21:48 GMT
</LI>
<LI><strong><A NAME="00840" HREF="msg00840.html">Re: [MUD-Dev] i got's a question for yall on the best way to do something..</A></strong>, 
Marc Hernandez <a href="mailto:marc#ias,jb.com">marc#ias,jb.com</a>, Thu 17 Jun 1999, 21:48 GMT
</LI>
</UL>
</LI>
<LI><strong><A NAME="00827" HREF="msg00827.html">[MUD-Dev] 3D Anarchy</A></strong>, 
Adam Wiggins <a href="mailto:adam#angel,com">adam#angel,com</a>, Thu 17 Jun 1999, 15:37 GMT
<LI><strong><A NAME="00826" HREF="msg00826.html">[MUD-Dev] Properties of computer languages</A></strong>, 
Caliban Tiresias Darklock <a href="mailto:caliban#darklock,com">caliban#darklock,com</a>, Thu 17 Jun 1999, 08:19 GMT
<UL>
<LI><strong><A NAME="00828" HREF="msg00828.html">Re: [MUD-Dev] Properties of computer languages</A></strong>, 
Jon Leonard <a href="mailto:jleonard#frost,slimy.com">jleonard#frost,slimy.com</a>, Thu 17 Jun 1999, 15:38 GMT
</LI>
</UL>
</LI>
</UL></BLOCKQUOTE>

</ul>
<hr>
<center>
[&nbsp;<a href="../">Other Periods</a>
&nbsp;|&nbsp;<a href="../../">Other mailing lists</a>
&nbsp;|&nbsp;<a href="/search.php3">Search</a>
&nbsp;]
</center>
<hr>
</body>
</html>