Creating New Records

You can create new records in the database within a script using the #NEW command. The first argument is the View|Database to create the record in. If blank, the current view in the current database is used. The following parameters are the Name and Value of each field you want to add. The Name1=Value1|Name2=Value2 syntax is also supported. You can also specify a database variable if you'd like. Some examples are:

#NEW Weapons Name "short sword" Damage "1d6" Hit 0 Dam 2

#NEW Weapons {Name="short sword"|Damage="1d6"|Hit=0|Dam=2}

#VAR NewWeapon ""
#ADDKEY NewWeapon Name "short sword"
#ADDKEY NewWeapon Damage "1d6"
#ADDKEY NewWeapon Hit 0
#ADDKEY NewWeapon Dam 2
#NEW Weapon @NewWeapon

Each of the above scripts creates a new weapon in the database.

The #NEW command can be used to create a new record in the database by capturing the result of an "identify" spell or command on the MUD. For example, let's look at the following MUD output for identifying a weapon:

> cast identify sword
Name: short sword Type: Weapon Cost: 1000 Weight: 5
Damage: 1d6 Hit: 0 Dam: 1

To create a new item based upon this output, we would first create an alias to cast identify, initialize out record variable and turn on a trigger class:

#ALIAS identify {#T+ identify;#VAR Item "";cast identify %1}

Then we would set up some triggers in the Identify class to parse the output and create a new variable:

#TRIGGER {Name: (*) Type: (%w) Cost: (%d) Weight: (%d)} {#VAR ItemType %2;#ADDKEY Item {Name="%1"|Cost=%3|Weight=%4}} identify
#TRIGGER {Damage: (*) Hit: (%d) Dam (%d)} {#ADDKEY Item {Damage=%1|Hit=%2|Dam=%3}} identify
#TRIGGER {$} {#T- identify;#IF (!%null(@Item)) {#NEW @ItemType @Item}} identify

The first two triggers capture the two lines of output from the identify spell and put the matched values into the NewItem database variable. The third trigger matches a blank line and turns off the identify triggers and if the NewItem has a value, adds it to the database using the #NEW command using whatever view corresponds to the object type (in this case, Weapon).

Now, each MUD output for the identify commands is different, and in most cases the output is different depending upon the type of object being identified. Thus, your triggers will likely be more complex than this example. However, given the4 flexibility of zMUD triggers and the scripting language for the database, almost anything is possible.

A more extensive (advanced) example

If you are an expert in writing triggers, then you have probably discovered the useful &VarName syntax which will capture a value from the MUD and automatically assign it to a variable. As a review, instead of doing

#TRIGGER {(%d)hp (%d)mana} {#VAR hp %1;#VAR mana %2}

you can just do:

#TRIGGER {&{hp}hp &{mana}mana} {}

Using the new dot notation syntax for database variables, the example from the previous section can be rewritten as:

#TRIGGER {Name: &Item.Name Type: &ItemType Cost: &Item.Cost Weight: &Item.Weight} {} identify
#TRIGGER {Damage: &Item.Damage Hit: &Item.Hit Dam &Item.Dam} {} identify
#TRIGGER {$} {#T- identify;#IF (!%null(@NewItem)) {#NEW @ItemType @Item}} identify

Note that the {} around the variable name are not needed since the space after the value delimits the end of the variable name.

OK, so all we have done here is save some typing. Where this syntax becomes powerful is when we want to handle the case where the identify output varies depending upon the object. For example, on many MUDs, if the item does not have a Hit bonus, the Hit:value is not even displayed in the identify output. In this case our second trigger would never fire. What we want is a separate trigger for each possible item property:

#TRIGGER {Name: &Item.Name Type: &ItemType} {} identify
#TRIGGER {Cost: &Item.Cost} {} identify
#TRIGGER {Weight: &Item.Weight} {} identify
#TRIGGER {Damage: &Item.Damage} {} identify
#TRIGGER {Hit: &Item.Hit} {} identify
#TRIGGER {Dam: &Item.Dam} {} identify

#TRIGGER {$} {#T- identify;#IF (!%null(@NewItem)) {#NEW @ItemType @Item}} identify

You can now expand this list of triggers to include any attributes that the identify command might display. This is a much cleaner and more powerful way to create new database items from the output of the MUD.



Contents Database Column calculations Working on the Database behind the scenes