Python Scripting

When you create a Trigger or Alias, you can select some scripting language support. This document describes the usage of the Python scripting engine.

The MudMagic Python script engine is nothing more than a gateway to your local Python install. As of version 1.9 of this software, Python support is now built-in with the software. To use Python in your aliases or triggers, simply select PYTHON as the command, and input your python script.


MudMagic python callbacks

There are certain commands that are looked for by the MudMagic client when dealing with a python script.


		send()   sends data back to the client
		messagebox()  creates a popup message box

Variables can be passed directly from MudMagic client to your Python script by using regular expression. For example, to catch the 2 arguments of: say one two , you would use a regular expression: ^say (.*) (.*) . The MudMagic client then sends these variables to your Python script in the form: _1 _2 . Please review the script below for further examples.


Python Examples

1. Alias: Say Test
Statement: ^say (.*) (.*)
Action: Script Python

one = _1
two = _2

send("say First was: "+one+" Second was: "+two)

2. Example provided by Davion
Alias: ^c (.*) (.*)

#Grab the arguments!
attempt = _1
target = _2

#Build us some spells!
spellList = ("fs", "firestorm"),
("fb", "fireball"),
("sc", "sex change")

#A simple function to cycle the spellList
def getSpell(sn):
        for x,y in spellList:
                if sn == x:
                        return y
        return None

#Grab the spell to cast
spell = getSpell(attempt)

#Lets see if it was found!
if spell:
        send("cast '"+spell+"' "+target)
else:
        messagebox("You don't know the "+attempt+" spell!")



Copyright  © 2004-02-26  MudMagic.Com