Menu

scripting

Raul Fajardo

ZopoClient provides a script mode which allows actions to be described in Python code. Triggers, Macros and Timers can describe actions this way. The code is executed when their event is triggered.

From the Python code, two objects are referenceable and variables can be defined or read. The two objects are the mud and the match objects.

Mud object

The mud object mainly allows the user to write information only to the output window or also to the mud using the following functions:
mud.write_info(text)
mud.write(text)

Match object

The match object gives information about the line which was recognized by the defined pattern. The following elements are always available:
match.string: the recognized line
match.prefix: line data previous to the defined recognition pattern
match.suffix: line data after the defined recognition pattern

Furthermore, special information can be defined in the pattern to be retrieved. This information is available through the match.regex object. In the comparison type AL Compatible, the user can define text to be specially recognized by writing %X (X is a number). The corresponding text is then available through the match.regex.group(Y) variable, where Y is the number of the special pattern in the pattern line.

Example:
AL Compatible pattern: HP: %12/%15
Mud line: HP: 20/50 SP: 12/80 EXP: 1,500
Match object:
match.string: HP: 20/50 SP: 12/80 EXP: 1,500
match.prefix:
match.suffix:
match.regex.group(1): 20
match.regex.group(2): 50

Furthermore, regular expressions can be used as comparison type. They follow the rules defined in the following link for describing the regular expression.
http://docs.python.org/library/re.html#regular-expression-syntax
If you read about the raw string requirement for expression description, you are not required to define patterns with r'' in the pattern entry line.

You can also read more about the match object, such as named groups under the following link:
http://docs.python.org/library/re.html#match-objects

And the test area for actions allow you to input some hypothetical line for which recognition of the pattern will be run. The window below shows the resulting match object for the given line. This helps the user to write his action.

Variables

Finally, variables can be defined, set and retrieved directly on user's action. Variables defined in one script can be retrieved by others to provide context defined actions. Example:

Trigger 1:
Exact-match Pattern: You don't see anything here by that name!
Action:
noheals = True

Trigger 2:
AL Compatible Pattern: HP: %1/%2
Action:
hp = int(match.regex.group(1))
hpmax = int(match.regex.group(2))
if hp < hpmax/3:
if noheals:
mud.write('back')
else:
mud.write('eat heal')

Be aware to respect the Python syntax which requires indentation for context block definition. The correct indentation is in the raw information for the wiki. But the wiki ignores it.


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.