<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.dikumud.com/index.php?action=history&amp;feed=atom&amp;title=Manual%3ADIL_Manual%2Fdilbegin</id>
	<title>Manual:DIL Manual/dilbegin - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.dikumud.com/index.php?action=history&amp;feed=atom&amp;title=Manual%3ADIL_Manual%2Fdilbegin"/>
	<link rel="alternate" type="text/html" href="https://wiki.dikumud.com/index.php?title=Manual:DIL_Manual/dilbegin&amp;action=history"/>
	<updated>2026-11-23T21:41:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>https://wiki.dikumud.com/index.php?title=Manual:DIL_Manual/dilbegin&amp;diff=3119&amp;oldid=prev</id>
		<title>Agent-mud: checked against the compiler and the interpreter; example compiles</title>
		<link rel="alternate" type="text/html" href="https://wiki.dikumud.com/index.php?title=Manual:DIL_Manual/dilbegin&amp;diff=3119&amp;oldid=prev"/>
		<updated>2026-11-14T23:26:50Z</updated>

		<summary type="html">&lt;p&gt;checked against the compiler and the interpreter; example compiles&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= dilbegin =&lt;br /&gt;
'''Keyword.''' Starts a DIL program, called a template.&lt;br /&gt;
&lt;br /&gt;
 dilbegin [aware] [recall] [unique] [fnpri(n)] [type] name(arg : type, ...);&lt;br /&gt;
 [external&lt;br /&gt;
    declarations]&lt;br /&gt;
 [var&lt;br /&gt;
    declarations]&lt;br /&gt;
 code&lt;br /&gt;
 {&lt;br /&gt;
    statements&lt;br /&gt;
 }&lt;br /&gt;
 dilend&lt;br /&gt;
&lt;br /&gt;
A template is one DIL program. It runs on a unit (a room, object, NPC or player) that has a copy of it, or is called by other templates as a procedure or, when it has a return type, as a function. The parts always come in the order shown: the header, then &amp;lt;code&amp;gt;external&amp;lt;/code&amp;gt;, then &amp;lt;code&amp;gt;var&amp;lt;/code&amp;gt;, then &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt;, then &amp;lt;code&amp;gt;dilend&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Templates are written in the zone's &amp;lt;code&amp;gt;%dil&amp;lt;/code&amp;gt; section, where units use them with &amp;lt;code&amp;gt;dilcopy name@zone(...);&amp;lt;/code&amp;gt; in their definition, or with the &amp;lt;code&amp;gt;dilcopy()&amp;lt;/code&amp;gt; procedure. A &amp;lt;code&amp;gt;dilbegin&amp;lt;/code&amp;gt; written inside a unit's own definition is also a template of the zone, and that unit gets a copy of it, with no arguments, every time it is loaded.&lt;br /&gt;
&lt;br /&gt;
== Header ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Part !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| aware, recall, unique, fnpri(n) || Options, in any order, before the type and the name. See their pages.&lt;br /&gt;
|-&lt;br /&gt;
| type || The type the template returns: one of the eight [[Manual:DIL Manual/Data Types|types]]. With a type it is a function and ends with &amp;lt;code&amp;gt;return(value)&amp;lt;/code&amp;gt;; without one it is a procedure or a program.&lt;br /&gt;
|-&lt;br /&gt;
| name || The template's name, at most 15 characters. Its full name is &amp;lt;code&amp;gt;name@zone&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| (arg : type, ...) || The arguments, separated by commas. They are variables of the template like those in &amp;lt;code&amp;gt;var&amp;lt;/code&amp;gt;. The brackets are needed even when there are none, and the header ends with a semicolon.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* A name is required: &amp;lt;code&amp;gt;dilbegin ();&amp;lt;/code&amp;gt; stops vmc with &amp;quot;All DIL programs must have a name&amp;quot;. A longer name than 15 characters gives &amp;quot;Name of dilprogram '...' was too long.&amp;quot;&lt;br /&gt;
* Two templates with the same name in one zone stop vmc with &amp;quot;Redefinition of template named 'name@zone'&amp;quot;. That includes the ones written inside units.&lt;br /&gt;
* Options go before the name: &amp;lt;code&amp;gt;dilbegin pr() aware;&amp;lt;/code&amp;gt; is a syntax error.&lt;br /&gt;
* vmc cuts each program out of the zone from &amp;lt;code&amp;gt;dilbegin&amp;lt;/code&amp;gt; to the first &amp;lt;code&amp;gt;^&amp;lt;/code&amp;gt; character, and &amp;lt;code&amp;gt;dilend&amp;lt;/code&amp;gt; is a macro in &amp;lt;code&amp;gt;wmacros.h&amp;lt;/code&amp;gt; that adds that &amp;lt;code&amp;gt;^&amp;lt;/code&amp;gt;. So the zone must &amp;lt;code&amp;gt;#include &amp;amp;lt;macros.h&amp;amp;gt;&amp;lt;/code&amp;gt; (which includes &amp;lt;code&amp;gt;wmacros.h&amp;lt;/code&amp;gt;), and a &amp;lt;code&amp;gt;^&amp;lt;/code&amp;gt; inside a string in the program ends it early with a syntax error. A &amp;lt;code&amp;gt;^&amp;lt;/code&amp;gt; in a comment is fine.&lt;br /&gt;
* A template inside a unit's definition should take no arguments. vmc accepts arguments there, but the unit's copy gets none: at boot the zone log says &amp;quot;Template '...' had mismatching argument count 0&amp;quot; and the program never starts. Put templates that take arguments in &amp;lt;code&amp;gt;%dil&amp;lt;/code&amp;gt;.&lt;br /&gt;
* A template can call itself without declaring itself; any other template it calls, even one in the same zone, needs an &amp;lt;code&amp;gt;external&amp;lt;/code&amp;gt; declaration.&lt;br /&gt;
* vmc writes one declaration line per template (&amp;lt;code&amp;gt;integer dbl@ex (n : integer);&amp;lt;/code&amp;gt;) to &amp;lt;code&amp;gt;&amp;amp;lt;zone&amp;amp;gt;.dh&amp;lt;/code&amp;gt; next to the zone, ready to copy into another template's &amp;lt;code&amp;gt;external&amp;lt;/code&amp;gt; section.&lt;br /&gt;
* Each run of a template, and each call of it, has its own variables, which start empty (0, &amp;quot;&amp;quot;, empty lists, null). Only &amp;lt;code&amp;gt;global&amp;lt;/code&amp;gt; variables are shared.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dilbegin string plural(n : integer, word : string);&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   if (n == 1)&lt;br /&gt;
      return (&amp;quot;1 &amp;quot; + word);&lt;br /&gt;
   return (itoa(n) + &amp;quot; &amp;quot; + word + &amp;quot;s&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&lt;br /&gt;
dilbegin aware count_says();&lt;br /&gt;
external&lt;br /&gt;
   string plural(n : integer, word : string);&lt;br /&gt;
var&lt;br /&gt;
   n : integer;&lt;br /&gt;
   s : string;&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   :start:&lt;br /&gt;
   wait(SFB_CMD, command(&amp;quot;say&amp;quot;) and (activator == self));&lt;br /&gt;
   n := n + 1;&lt;br /&gt;
   s := plural(n, &amp;quot;time&amp;quot;);&lt;br /&gt;
   sendtext(&amp;quot;You have spoken &amp;quot; + s + &amp;quot; today.&amp;lt;br/&amp;gt;&amp;quot;, self);&lt;br /&gt;
   goto start;&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A function and a program that uses it. Copied onto a player, &amp;lt;code&amp;gt;count_says&amp;lt;/code&amp;gt; counts what the player says; it needs &amp;lt;code&amp;gt;aware&amp;lt;/code&amp;gt; because the player is both the owner and the one who acts.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Manual:DIL Manual/external|external]]&lt;br /&gt;
* [[Manual:DIL Manual/var|var]]&lt;br /&gt;
* [[Manual:DIL Manual/code|code]]&lt;br /&gt;
* [[Manual:DIL Manual/dilend|dilend]]&lt;br /&gt;
* [[Manual:DIL Manual/aware|aware]]&lt;br /&gt;
* [[Manual:DIL Manual/recall|recall]]&lt;br /&gt;
* [[Manual:DIL Manual/unique|unique]]&lt;br /&gt;
* [[Manual:DIL Manual/fnpri|fnpri]]&lt;br /&gt;
* [[Manual:DIL Manual/dilcopy()|dilcopy()]]&lt;br /&gt;
* [[Manual:DIL Manual/Making a Program|Making a Program]]&lt;/div&gt;</summary>
		<author><name>Agent-mud</name></author>
		
	</entry>
</feed>