Top Mud Sites Forum Return to TopMudSites.com
Go Back   Top Mud Sites Forum > Mud Development and Administration > MUD Coding
Click here to Register

Reply
 
Thread Tools
Old 10-26-2004, 08:32 PM   #1
Dubthach
New Member
 
Join Date: Apr 2002
Posts: 21
Dubthach is on a distinguished road
So I'm messing around with writing a mud. It'll never get done, but its a mechanism for me to get better at a few skills.

Anyway.

One of the things I need at a basic level is a routine that matches up the command input by the player with a method call in the engine. I suppose the most basic way of doing this is to use a massive switch statement, but I was wondering if anyone has a more elegant way of doing it?

Thanks,
Dub
Dubthach is offline   Reply With Quote
Old 10-26-2004, 08:58 PM   #2
Yui Unifex
Senior Member
 
Join Date: Apr 2002
Location: Florida
Posts: 323
Yui Unifex is on a distinguished road
Send a message via ICQ to Yui Unifex Send a message via AIM to Yui Unifex
Question

Of course there's a better way to do it =). Despite being a horrendous design decision, gigantic lists of switch and if statements don't cut it because they can't do partial matching of a command name.

You most likely want to store command objects in a dynamically extendable table. Of course it varies from mud to mud, but in the command object I keep an access control (so that the 'smite' command is not made available to normal players), the name of the command, a list of target specifications, and a function pointer or pointer to member function or delegate or code object or whatever so you can call the code you need when necessary.

The target specification is also very important and very overlooked. Many commands such as 'tell', 'kill', 'give', etc., are targetted at an element in the game. It should be the command dispatcher's job to locate those targets specified in the command string and pass them as an array when the actual command code is called into.

I refer you to the section on commands in my Aetas Concepts and Architecture document for some examples of how I define commands.
Yui Unifex is offline   Reply With Quote
Old 10-26-2004, 09:59 PM   #3
Dubthach
New Member
 
Join Date: Apr 2002
Posts: 21
Dubthach is on a distinguished road
Yes, I thought of a pointer to function, but I am using C# and don't know how (if it is possible without unsafe code) to do that. I'll think about it for a bit.
Dubthach is offline   Reply With Quote
Old 10-26-2004, 10:51 PM   #4
Yui Unifex
Senior Member
 
Join Date: Apr 2002
Location: Florida
Posts: 323
Yui Unifex is on a distinguished road
Send a message via ICQ to Yui Unifex Send a message via AIM to Yui Unifex
Question

Not only is it possible with C#, it's much, much easier because you can use either delegates or reflection to get at what you need. I would suggest reflection since you can't retarget (change the 'this' target) of a non-static delegate, and static delegates always have a null 'this' target. It's a terrible limitation I know, but they don't have me designing these languages so I'm content to merely complain about them on mud forums...

The reflection method is very easy. Say you've got an object called 'Player' which can execute the 'CmdLook' method when the player types 'look'

[code] using System.Reflection;
...
Type playerType = typeof(Player);
MethodInfo lookMethod = playerType.GetMethod("CmdLook");[/quote]
Now say you want to invoke the method with a played named 'actor' as 'this', a target player named 'target', and a string of miscellaneous text named 'args':
[code] lookMethod.Invoke(actor, new object[] {target, args});[/quote]
Which will jump into code like this on the Player object:
[code] class Player...
public void CmdLook (Player target, string args) {
...
}[/quote]

It's extremely simple. Look into the System.Type.GetMethod method.
Yui Unifex is offline   Reply With Quote
Old 10-27-2004, 12:01 AM   #5
Dubthach
New Member
 
Join Date: Apr 2002
Posts: 21
Dubthach is on a distinguished road
Thanks much, I'll look into it.
Dubthach is offline   Reply With Quote
Reply


Thread Tools


command processor - Similar Threads
Thread Thread Starter Forum Replies Last Post
Features of a MUD command parser. Drealoth Advanced MUD Concepts 15 04-27-2006 03:08 PM
Jog Command Jaegar MUD Coding 4 04-09-2004 05:41 AM
Switch command Verboden Faction MUD Coding 8 05-15-2003 10:31 PM
Command trigger for progs Jaegar MUD Coding 1 04-03-2003 07:41 PM
Chown Command Verboden Faction MUD Coding 9 03-23-2003 08:12 PM

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

All times are GMT -4. The time now is 02:13 PM.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Style based on a design by Essilor
Copyright Top Mud Sites.com 2014