Sign in to follow this  

Python Mud Command Loader Opinions

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am working on a command loader for a mud framework I am developing. Basically what it will be is a loader that allows for loading and removal of command objects from memory. So essentially it is a script loader. I am working on the basic class known as script atm. Just looking for some opinions on the implementation of the class. The class is meant to be derived by every command script.
class Script:
	def __init__(self)
		self.data = {}
		
	def addScriptData(scriptdata)
		self.data = scriptdata
	
	def execute()
		pass

Share this post


Link to post
Share on other sites
This really isn't enough to comment on. The class as shown here is vapor...just a container for a dictionary. Your class should provide all of the operations needed so that you never need to work with that data directly (from outside the class).

Share this post


Link to post
Share on other sites
Well the concept is the client sends a command. When the server gets the command it is split up and sent to the command script manager from there the manager sends the data to the appropriate script object and then executes the script. Then the result is sent back to the client. That class is meant to do nothing really just a interface for a derived class. Was looking for input on the actual design of that class. Maybe there is a better way to design it.

Share this post


Link to post
Share on other sites
It is not suppose to do anything it is merely a interface to derive from. It is basically a format that every command script for the mud has to follow. Again I am just looking for opinions to see if I am on the right track. Here is a example on how it is to be used.


class MoveNorth(Script):
def __init__(self)
self.data = {}

def addScriptData(scriptdata)
self.data = scriptdata

def execute()
#move the character north one square and display the square discription

Share this post


Link to post
Share on other sites
I'm sure there is a better way but it's hard to say with so little info to go on. Basically these Script objects don't really need to exist. You're using them like function objects but that is unnecessary because in Python functions are objects. Just define regular "global" functions and store them directly in your "manager" by name as if they were any other kind of variable. Pass the data to them as an argument. I can try to give better advice if you can provide more detail about what the scriptdata dictionary looks like, how the Script instances are stored, how they are selected by the manager, etc.

Share this post


Link to post
Share on other sites
Ok I will try to explain in detail. Script is a Interface. A contract that all Command Scripts must follow. This allows for a common way to call all commands the game parses. This allows for the Command Script manager to be able to hot load scripts without having to restart the server and makes it easier to use introspection to call the command. scriptdata is just a ordinary dictionary that holds key and value pairs of data that the client is passing to the server. For instance if attacking a mob the command /attack rat would send a command to the server stored as say:

1234||attack||rat

The server would break this down into a dictionary

PlayerID = 1234, command = attack, target = rat

this data is passed to the script so it can do whatever it does and send the results back to the client.

Share this post


Link to post
Share on other sites
In Python there's little point having a base class as an interface. That's something you'd do in Java or C++ because of the static typing, but in Python you don't need that. The only aspects of this 'contract' you have here are that data goes in, and that you execute the script on that data. So all you really need is (a) a function, and (b) the data as parameters to that function. Each script can therefore just be a function. And you store a list of those functions, instead of a list of classes which implement a known function.

Share this post


Link to post
Share on other sites
Ok thankyou that is what I was looking for. I was under the thought that like in C++, java, C# you can call members of a class from a interface instead of the object itself. Thanks for the input again. I will make some modifications to my system.

Share this post


Link to post
Share on other sites

This topic is 3592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this