MushClient

by Alef

Back to Mechanic's Corner.

Alef2005-02-23 17:01:33
Ok I'm about to start to learn how to script myself a system. Now which would be better for me, with no scripting knowledge as of yet, Python or VB?
Unknown2005-02-23 18:23:38
Between just those two languages? I'd say that VB is easier to learn for a non-programmer. Python is more powerful. Myself, I've been happy using Lua for my scripts. smile.gif
Eldanien2005-02-23 19:41:39
If I might make a suggestion off that list for non-programmers: do the JScript. It's just as easy as VBScript, but slightly less prone to datatype mangling. It causes fewer headaches. Both languages use the same scripting engine, so if you're set to code in one you can code in the other.

If you're willing to put a bit more into learning code, Python has a strong speed edge in the overall if you use smart coding practice. Keep variables in script, rather than using MUSHclient variables, for example, so as to reduce callbacks to MUSHclient.
Alef2005-02-23 20:21:59
I'm in no rush to learn to code and I have plenty of time, so I'll give Python a quick look, if it all looks wonky I'll start in JScript or VBscript.
Tias2005-02-25 09:06:53
QUOTE(Alef @ Feb 23 2005, 03:21 PM)
I'm in no rush to learn to code and I have plenty of time, so I'll give Python a quick look, if it all looks wonky I'll start in JScript or VBscript.
58191



I use Python with Mushclient. Python is way easy to learn just follow the tutorial in they Documentation. If you have any questions though I could probably help just PM me.
Asarnil2005-02-25 09:34:57
I despise anyone who even thinks of using VBscript.
Shryke2005-02-26 23:19:46
just got python & mushclient, now i cant figure out how to save a script... do I write it in python then save it, or do I write it in notepad then somehow change it to python...? someone please help me I am very lost....
Tias2005-02-27 08:29:31
QUOTE(Shryke @ Feb 26 2005, 06:19 PM)
just got python & mushclient, now i cant figure out how to save a script... do I write it in python then save it, or do I write it in notepad then somehow change it to python...?  someone please help me I am very lost....
61023



You can use IDLE or PythonWin (I prefer pythonwin) to write and save your scripts. Or you can use notepad too just make sure you keep the indents right and you'll need to save them with the pys extension for mushclient to load them.
Unknown2005-02-27 08:43:35
What are the advantages of using Python over VBScript?
Eldanien2005-02-27 08:50:57
Less code, same work done. Better structure. More elegant. More precise. More... just about everything worthwhile, except ease.

However, it's not such a huge difference that choosing one over the other will ruin you.

If you were equally skilled in both, you'd go Python.

If you're not a programmer, learning VB will be somewhat easier, since it tolerates a bit more sloppiness.
Ethelon2005-02-27 13:33:24
hehe, look over my lines of VBscript...there's some sloppiness in there! I was thinking about switching the whole thing over to PYthon but just haven't found the time yet.
Shryke2005-02-27 15:45:38
yay! then maybe you could help my lost and demented soul!
Unknown2005-02-27 16:41:19
Shryke2005-02-27 16:56:22
it helped, but its not gonna make it a whole lot easier to make a system eh?
Unknown2005-02-27 17:40:41
Making a system is equally simple. Especially with Python. Certainly making an extensive and all encompassing one isn't so easy, but trying to do that from the start is a bad idea anyways - it's better to make something small and working, then try to make something big that will never get finished. Here's a simple combat system for you. It consists of the following parts:

1. Triggers to catch afflictions and cures
2. Code to store affliction states
3. Code to cure afflictions

The script is:

CODE

from PyAchaea.Avatar import Avatar
my_avatar = Avatar(world)           #standard initialization of PyAchaea

my_avatar.addBalance("herb", 1.5)      #add a balance named "herb" with a period of 1.5 seconds

def SelectAffliction(name, output, wildcs):
   lst = name.split("_")       #split the trigger name around "_"
   type = lst               #first part of the trigger name defines whether this is an affliction or a cure
   affl = lst               #second part defines what affliction it is (affliction's name)
   number = lst             #third part is a trigger number, so you can tell which trigger exactly fired
   
   if type == "affliction":            #if the trigger signals an affliction
       my_avatar.addAffl(affl)         #add the affliction to the internal list
   elif type == "cure":                #else, if the trigger signals a cure
       my_avatar.remAffl(affl)         #remove the affliction from the internal list

def CureHerbAfflictions():
   if my_avatar.isAffl("clumsiness"):     #if you have paralysis
       world.Send("cure clumsiness")   #send the curing commands
       my_avatar.setBalance("herb", False)     #set the herb balance to False

   elif my_avatar.isAffl("stupidity"):    #else, if you have stupidity
       world.Send("cure stupidity")    #send the curing commands
       my_avatar.setBalance("herb", False)     #set the herb balance to False

my_avatar.setBalanceCallback("herb", CureHerbAfflictions)   #bind the CureHerbAfflictions function to the herb balance,
                                               #this function will be called periodically if herb balance is True


That's all you pretty much need for a simple curing system - it contains a function that keeps track of afflictions (SelectAffliction), a function that cures herb afflictions (CureHerbAfflictions), and a single balance object (herb). The balance requires you to have PyAchaea, available at pyachaea0.tripod.com.

Then you'll also need some triggers. The triggers that catch afflictions must be named as "affliction_afflname_trignumber", for example: "affliction_stupidity_1". Those that catch cure lines are named "cure_afflname_trignumber", for example: "cure_stupidity_1". Trigger numbers are only used to set the names for the same afflictions apart, as well as for being able to tell which trigger specifically fired for this or that affliction.

In order to make this system track more afflictions, you just need to keep adding "elif" statements bellow the elif my_avatar.isAffl("stupidity"): one in the CureHerbAfflictions function. And triggers obviously.

To finalize it you'll also need a timer to "pulse" the PyAchaea engine. Add a timer with a precision of 0.5 seconds, make it send to script and put the following in its' Send field:

CODE

my_avatar.pulse()


That's a minimal combat system for you.


Well, I sure got the script all wrong the first time.