Difference between revisions of "Manual:Zone Manual/The DIL Section"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the current code (wiki review 2026-11-15))
 
Line 1: Line 1:
 
== The DIL section ==
 
== The DIL section ==
 +
The chapters before this one build rooms, objects and NPCs that sit still. To make them do something (an NPC that greets players, a door that locks itself at night, a room full of acid) you give them a DIL program. This chapter explains what DIL is and the three ways to put it in a zone. How to write DIL is the subject of the [[Manual:DIL Manual|DIL Manual]].
  
−
When I first thought of writing this manual I had planned to leave
 
−
DIL totally out of it.  The DIL language always confuses new Builders
 
−
and complicates teaching simple rooms, objects, and NPCs.  It became
 
−
clear to me though that DIL is such a part of the server that I at least
 
−
had to mention it hear so builders would know where to look and
 
−
what DIL could do for them when they got to the point where they were
 
−
ready to use it.
 
 
=== What is DIL? ===
 
=== What is DIL? ===
 +
DIL is the scripting language of DikuMUD3. A DIL program is written in a zone file, and vmc compiles it with the rest of the zone. The server runs it on a unit (a room, an object, an NPC or a player), which the program calls <code>self</code>. Most programs wait for something to happen (a player arrives, a command is typed nearby, time passes), act on it, and wait again.
  
−
DIL is short for, Data-based instructional language.  Not to be
+
A large part of the game is written in DIL, in the zones that come with the server: most of the commands players type, the spells and skills, the quests, the guilds and their teachers, the message boards and the mail. So DIL can do far more than a builder usually needs, and for most of what a builder needs, a program already exists.
−
confused with Database since DIL is nothing like a database.  Data-based
 
−
means that the language works on a fixed set of units like objects,
 
−
NPCS, and rooms and is designed to give them a life of their own.
 
−
Unlike on many of the mud servers on the internet DIL is not an
 
−
interpreted language it is a compiled language which gives you the user
 
−
much more safe guards against crashes and slow code.
 
  
−
DIL also provides a full set of data types to allow you to do
+
=== DIL in a zone ===
−
calculations or store information from players.  The DIL language can
+
There are three ways:
−
even deal with file access and it can add fields and information to the
 
−
players if needed.  In short the VME server has its own internal
 
−
functional language that will allow you to do just about anything you
 
−
want to.
 
−
=== What can DIL be used for? ===
 
  
−
...
+
'''1. Use a ready-made program.''' A <code>dilcopy</code> line in a unit puts a copy of a program (a '''template''') on every copy of that unit. The template is named <code>name@zone</code>, and its arguments go in parentheses, followed by a semicolon:
 +
<pre>
 +
dilcopy death_room@function(PULSE_SEC * 5, 20, "The acid burns your skin!");
 +
</pre>
 +
<code>function.zon</code> holds many such templates: guards, aggressive NPCs, death rooms, rooms that move players on, and more. Read the template's <code>dilbegin</code> line and the comment above it in its zone to see what it does and what arguments it takes. vmc checks neither the name nor the arguments: a template that doesn't exist shows up only when the server boots, in its log.
  
−
It is hard to explain what all DIL can be used for with out just
+
'''2. Write a program inside a unit.''' A program written between <code>dilbegin</code> and <code>dilend</code> among a unit's fields runs on that unit. It takes no arguments, and its name must be unique in the zone.
−
writing a list of things that have already been done in DIL so here is the
 
−
list.
 
−
* All spells
 
−
* 60% of the commands and skills and growing
 
−
* Administrator commands
 
−
* Movement commands
 
−
* look commands
 
−
* 200+ quests and growing
 
−
* Message boards
 
−
* Mail system
 
−
* Clan system
 
−
* Automated Newbie guides
 
−
* object restrictions
 
−
* Death Sequence
 
−
* Magical combat system
 
−
* NPC agressive functions
 
−
* personalized Familiars
 
−
* personalized pets
 
−
* Deck of cards
 
−
* Chess board
 
−
* dice
 
−
* online AD&amp;D game playing system
 
−
* Communication channels
 
−
* automated wedding chapel
 
  
−
Realize this is only a small list of things that can be done in
+
'''3. Write templates in the <code>%dil</code> section.''' A template there can be used with <code>dilcopy</code> by any unit, in this zone or any other, and called from other programs. Use this for a program that several units share, or that takes arguments.
−
DIL.  In the future we hope to be able to add the ability to easily
 
−
change combat and all the character update features using DIL. These
 
−
things can be currently done with DIL but it takes a lot of knowledge
 
−
and work which we hope to simplify.
 
−
=== Where do I get more information on DIL? ===
 
  
−
The online DIL reference guide is the most authoritative guide
+
The zone must include <code>macros.h</code>: <code>dilend</code> is a macro defined there, and vmc can't find the end of a program without it.
−
currently for DIL. It can be found at
 
−
http://www.valhalla.com and follow the builders links.
 
  
−
In the near future we hope to have an entire new DIL manual that
+
=== An example ===
−
will teach, a person who has never coded all the way to people who are
+
This zone uses all three: a template of its own in <code>%dil</code>, used by the cellarer with <code>dilcopy</code>; a program written inside the cellarer; and <code>death_room@function</code> on the vault. It compiles as <code>cellar.zon</code>:
−
already professional coders, to use DIL. For now if you can not find
+
<pre>
−
what you need in the DIL reference manual you can join the DIL email list
+
#include <macros.h>
−
at dil-request@valhalla.com or you can send a mail to
+
 
−
whistler@valhalla.com.  Until and even after the new DIL
+
%zone cellar
−
manual is written we will always try to help you as much as possible
+
title "The Wine Cellar"
−
while you are getting started. It is important that you at least try
+
lifespan 20
−
and look through the DIL reference before asking a lot of questions
+
reset RESET_ANYHOW
−
because many of the questions may be answered already.
+
creators {"manual"}
 +
 
 +
%dil
 +
 
 +
/* A template of this zone: any unit, in any zone, can use it
 +
  with dilcopy greeting@cellar("...");                        */
 +
dilbegin greeting(text : string);
 +
code
 +
{
 +
  :start:
 +
  wait(SFB_DONE, command(CMD_AUTO_ENTER) and (activator.type == UNIT_ST_PC));
 +
  exec("say " + text, self);
 +
  goto start;
 +
}
 +
dilend
 +
 
 +
%rooms
 +
 
 +
stairs
 +
title "Cellar stairs"
 +
descr
 +
"Worn stone steps lead down into the dark."
 +
down to vault;
 +
end
 +
 
 +
vault
 +
title "The acid vault"
 +
descr
 +
"The air stings your eyes and the floor bubbles."
 +
up to stairs;
 +
// A ready-made template from function.zon: 20 damage every 5 seconds.
 +
dilcopy death_room@function(PULSE_SEC * 5, 20, "The acid burns your skin!");
 +
end
 +
 
 +
%mobiles
 +
 
 +
cellarer
 +
names {"cellarer", "old man", "man"}
 +
title "the cellarer"
 +
descr "The old cellarer is counting bottles."
 +
extra {}
 +
"A bent old man with dusty hands."
 +
M_HUMAN_WARRIOR_AXE(10, SEX_MALE)
 +
dilcopy greeting@cellar("Mind the acid down there!");
 +
 
 +
// A program written inside the unit: it runs on this NPC only.
 +
dilbegin cellar_count();
 +
code
 +
{
 +
  heartbeat := PULSE_SEC * 60;
 +
  :start:
 +
  pause;
 +
  exec("emote counts the bottles again.", self);
 +
  goto start;
 +
}
 +
dilend
 +
end
 +
 
 +
%reset
 +
 
 +
load cellarer into stairs
 +
 
 +
%end
 +
</pre>
 +
vmc prints a line for each program it compiled:
 +
<pre>
 +
VMC 2.0 Copyright (C) 2001 by Valhalla [Nov 14 2026]
 +
VMC Compiled with [-DDMSERVER -DPOSIX -DVMC -DVMC_SRC -DLINUX -DMUD_DEBUG]
 +
Compiling 'cellar.zon'
 +
DIL (line    13)tmpl : greeting            (  89 bytes)
 +
DIL (line    53)tmpl : cellar_count        ( 109 bytes)
 +
VMC Done.
 +
</pre>
 +
The <code>greeting</code> program waits until a player has walked into the room, makes the cellarer say its text, and waits again. <code>cellar_count</code> wakes about once a minute and makes him count his bottles. In the game, <code>[[Wizhelp/Wstat|wstat]]</code> with <code>func</code> lists the programs a unit runs.
 +
 
 +
=== Where to read more ===
 +
The [[Manual:DIL Manual|DIL Manual]] teaches the language. Start with these chapters:
 +
* [[Manual:DIL Manual/Making a Program|Making a Program]]: where programs are written, their parts, how they run and wait, and how they are compiled.
 +
* [[Manual:DIL Manual/Data Types|Data Types]] and [[Manual:DIL Manual/DIL Constructs|DIL Constructs]]: variables, <code>if</code>, <code>while</code>, <code>goto</code> and the rest.
 +
* [[Manual:DIL Manual/Messages|Messages]]: the events a program waits for, such as <code>SFB_DONE</code> and <code>SFB_CMD</code>.
 +
* [[Manual:DIL Manual/Functions|Functions]]: templates that call each other, also across zones.
 +
* [[Manual:DIL Examples|DIL Examples]]: complete programs from the zones that come with the server.
 +
* [[Manual:DIL Manual (Full Listing)|Full Listing]]: every keyword, function and field of DIL on one page.
 +
 
 +
The chapters on rooms, objects and NPCs show the ready-made templates that suit each of them.
  
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual:Zone_Manual/Color_and_Formatting_Codes/Color_code_descriptions_and_examples|Previous: Color code descriptions and examples]]</div>
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual:Zone_Manual/Color_and_Formatting_Codes/Color_code_descriptions_and_examples|Previous: Color code descriptions and examples]]</div>
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: right;float:right;width:50%;'>[[Manual:Zone_Manual/Appendices|Next: Appendices]]</div>
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: right;float:right;width:50%;'>[[Manual:Zone_Manual/Appendices|Next: Appendices]]</div>

Latest revision as of 06:20, 15 November 2026

The DIL section

The chapters before this one build rooms, objects and NPCs that sit still. To make them do something (an NPC that greets players, a door that locks itself at night, a room full of acid) you give them a DIL program. This chapter explains what DIL is and the three ways to put it in a zone. How to write DIL is the subject of the DIL Manual.

What is DIL?

DIL is the scripting language of DikuMUD3. A DIL program is written in a zone file, and vmc compiles it with the rest of the zone. The server runs it on a unit (a room, an object, an NPC or a player), which the program calls self. Most programs wait for something to happen (a player arrives, a command is typed nearby, time passes), act on it, and wait again.

A large part of the game is written in DIL, in the zones that come with the server: most of the commands players type, the spells and skills, the quests, the guilds and their teachers, the message boards and the mail. So DIL can do far more than a builder usually needs, and for most of what a builder needs, a program already exists.

DIL in a zone

There are three ways:

1. Use a ready-made program. A dilcopy line in a unit puts a copy of a program (a template) on every copy of that unit. The template is named name@zone, and its arguments go in parentheses, followed by a semicolon:

dilcopy death_room@function(PULSE_SEC * 5, 20, "The acid burns your skin!");

function.zon holds many such templates: guards, aggressive NPCs, death rooms, rooms that move players on, and more. Read the template's dilbegin line and the comment above it in its zone to see what it does and what arguments it takes. vmc checks neither the name nor the arguments: a template that doesn't exist shows up only when the server boots, in its log.

2. Write a program inside a unit. A program written between dilbegin and dilend among a unit's fields runs on that unit. It takes no arguments, and its name must be unique in the zone.

3. Write templates in the %dil section. A template there can be used with dilcopy by any unit, in this zone or any other, and called from other programs. Use this for a program that several units share, or that takes arguments.

The zone must include macros.h: dilend is a macro defined there, and vmc can't find the end of a program without it.

An example

This zone uses all three: a template of its own in %dil, used by the cellarer with dilcopy; a program written inside the cellarer; and death_room@function on the vault. It compiles as cellar.zon:

#include <macros.h>

%zone cellar
title "The Wine Cellar"
lifespan 20
reset RESET_ANYHOW
creators {"manual"}

%dil

/* A template of this zone: any unit, in any zone, can use it
   with dilcopy greeting@cellar("...");                        */
dilbegin greeting(text : string);
code
{
   :start:
   wait(SFB_DONE, command(CMD_AUTO_ENTER) and (activator.type == UNIT_ST_PC));
   exec("say " + text, self);
   goto start;
}
dilend

%rooms

stairs
title "Cellar stairs"
descr
"Worn stone steps lead down into the dark."
down to vault;
end

vault
title "The acid vault"
descr
"The air stings your eyes and the floor bubbles."
up to stairs;
// A ready-made template from function.zon: 20 damage every 5 seconds.
dilcopy death_room@function(PULSE_SEC * 5, 20, "The acid burns your skin!");
end

%mobiles

cellarer
names {"cellarer", "old man", "man"}
title "the cellarer"
descr "The old cellarer is counting bottles."
extra {}
"A bent old man with dusty hands."
M_HUMAN_WARRIOR_AXE(10, SEX_MALE)
dilcopy greeting@cellar("Mind the acid down there!");

// A program written inside the unit: it runs on this NPC only.
dilbegin cellar_count();
code
{
   heartbeat := PULSE_SEC * 60;
   :start:
   pause;
   exec("emote counts the bottles again.", self);
   goto start;
}
dilend
end

%reset

load cellarer into stairs

%end

vmc prints a line for each program it compiled:

VMC 2.0 Copyright (C) 2001 by Valhalla [Nov 14 2026]
VMC Compiled with [-DDMSERVER -DPOSIX -DVMC -DVMC_SRC -DLINUX -DMUD_DEBUG]
Compiling 'cellar.zon'
DIL (line    13)tmpl : greeting             (   89 bytes)
DIL (line    53)tmpl : cellar_count         (  109 bytes)
VMC Done.

The greeting program waits until a player has walked into the room, makes the cellarer say its text, and waits again. cellar_count wakes about once a minute and makes him count his bottles. In the game, wstat with func lists the programs a unit runs.

Where to read more

The DIL Manual teaches the language. Start with these chapters:

  • Making a Program: where programs are written, their parts, how they run and wait, and how they are compiled.
  • Data Types and DIL Constructs: variables, if, while, goto and the rest.
  • Messages: the events a program waits for, such as SFB_DONE and SFB_CMD.
  • Functions: templates that call each other, also across zones.
  • DIL Examples: complete programs from the zones that come with the server.
  • Full Listing: every keyword, function and field of DIL on one page.

The chapters on rooms, objects and NPCs show the ready-made templates that suit each of them.

Previous: Color code descriptions and examples
Next: Appendices