zMUD COM Using zMUD

Updated: February 01, 2002 by Mike Potter (Zugg)

Related Articles:

This article describes how to control zMUD using the zMUD COM interface from within the zMUD scripting language itself.

NOTE: This document refers to zMUD version 6.26 and later.

Introduction

I'm going to assume you already know what COM is and how to use it.  If not, see the COM Programming in zMUD article.

Since zMUD allows you to create and access COM objects, and zMUD itself is a COM object, it seems natural to ask if you can control zMUD using COM from within a zMUD script.  The answer is, of course!  The next question is: "Why would you want to?"

The COM interface for zMUD exposes a much lower-level object model for aliases, triggers, etc than the normal zMUD scripting language.  For example, what if you wanted to change the "Case Sensitive" property of one of your triggers from a script?  Well, you can use the #TRIGGER command to create the trigger, but there is no way to just simply change the Case Sensitive option using the #TRIGGER command without recreating the entire trigger.

Using the zMUD Com interface, it's pretty simple.  In a language like Visual Basic, you'd do something like this:

Dim zMUD as Object
Dim Sess as Object
Dim Trig as Object

Set zMUD = CreateObject("zMUD.Application")
Set Sess = zMUD.CurrentSession
Set Trig = Sess.TriggerNum(0)
Trig.Current.CaseSens = false

Set Trig = nothing
Set Sess = nothing
Set zMUD = nothing

That would fetch the first trigger and set the Case Sensitive option of the current trigger state to false.

The %session variable

In zMUD, it's a bit easier.  zMUD already provides a COM object link to the current session in the %session system variable.  So, there is no need to create any COM objects, it's already created for you (after all, it seems silly to have to create a link to a program you are already running in).

So, the zMUD code to set the Case Sensitive property of the first trigger to false is simply:

#VAR Trig %session.TriggerNum(0)
#VAR Trig.Current.CaseSens 0

Easy!

Here is another example.  This displays the names of all the aliases currently defined:

#VAR Count %session.NumAliases
#LOOP 0,Count-1 {#ECHO %session.AliasNum(%i).Name}

The possibilities are endless!

The %zmud variable

Just as the %session variable provides access to the current session object, the %zmud variable provides access to the global zMUD.Application object.  For example:

#ECHO %zmud.zMUDVersion

will display the current version of zMUD using the COM interface.