<?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%2Fvar</id>
	<title>Manual:DIL Manual/var - 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%2Fvar"/>
	<link rel="alternate" type="text/html" href="https://wiki.dikumud.com/index.php?title=Manual:DIL_Manual/var&amp;action=history"/>
	<updated>2026-11-23T21:08: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/var&amp;diff=3120&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/var&amp;diff=3120&amp;oldid=prev"/>
		<updated>2026-11-14T23:26:54Z</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;= var =&lt;br /&gt;
'''Keyword.''' Starts the variable declarations of a template.&lt;br /&gt;
&lt;br /&gt;
 var&lt;br /&gt;
    name : type;&lt;br /&gt;
    name, name, ... : type;&lt;br /&gt;
    name : stringlist global key@zone;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;var&amp;lt;/code&amp;gt; section comes after the header and the &amp;lt;code&amp;gt;external&amp;lt;/code&amp;gt; section, and before &amp;lt;code&amp;gt;code&amp;lt;/code&amp;gt;. It is optional. Each line names one or more variables and their type, and ends with a semicolon (vmc lets the last one go without).&lt;br /&gt;
&lt;br /&gt;
The template's arguments are variables too, declared in the header instead. Every run of a template, and every call of it, gets its own set of variables, which start empty: 0, &amp;quot;&amp;quot;, an empty list, or null.&lt;br /&gt;
&lt;br /&gt;
== What a variable keeps ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type !! After a wait (pause, wait, a heartbeat) !! When the unit is saved and loaded&lt;br /&gt;
|-&lt;br /&gt;
| [[Manual:DIL Manual/integer|integer]], [[Manual:DIL Manual/string|string]], [[Manual:DIL Manual/stringlist|stringlist]], [[Manual:DIL Manual/intlist|intlist]] || kept || saved with the unit&lt;br /&gt;
|-&lt;br /&gt;
| [[Manual:DIL Manual/unitptr|unitptr]] || null, unless the unit is &amp;lt;code&amp;gt;secure&amp;lt;/code&amp;gt;d || null&lt;br /&gt;
|-&lt;br /&gt;
| [[Manual:DIL Manual/extraptr|extraptr]] || null || null&lt;br /&gt;
|-&lt;br /&gt;
| [[Manual:DIL Manual/zoneptr|zoneptr]], [[Manual:DIL Manual/cmdptr|cmdptr]] || kept || null&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* Names ignore case: &amp;lt;code&amp;gt;MyVar&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;myvar&amp;lt;/code&amp;gt; are the same variable.&lt;br /&gt;
* Every function, field and built-in variable of DIL is a reserved word, so &amp;lt;code&amp;gt;name&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;names&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;npcs&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;objs&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;key&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;level&amp;lt;/code&amp;gt; and the like can't be variable names. vmc reports a syntax error with that word as the token. Use &amp;lt;code&amp;gt;pname&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;u&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;kw&amp;lt;/code&amp;gt;.&lt;br /&gt;
* A variable can't have the same name as another variable or an argument (&amp;quot;Duplicate variable identifier&amp;quot;).&lt;br /&gt;
* A template has at most 255 variables, arguments included.&lt;br /&gt;
* Saved values are thrown away, and the program starts over, when the template's variables have changed (names, types or order) since the unit was saved.&lt;br /&gt;
* &amp;lt;code&amp;gt;global key@zone&amp;lt;/code&amp;gt; after the type shares one value between every program that names the same key; see [[Manual:DIL Manual/global|global]].&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dilbegin greeter(greeting : string);&lt;br /&gt;
var&lt;br /&gt;
   pc : unitptr;&lt;br /&gt;
   seen : stringlist;&lt;br /&gt;
   count, i : integer;&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   :start:&lt;br /&gt;
   wait(SFB_DONE, command(CMD_AUTO_ENTER) and (activator.type == UNIT_ST_PC)&lt;br /&gt;
        and (activator.outside == self.outside));&lt;br /&gt;
   pc := activator;&lt;br /&gt;
   if (pc.name in seen)&lt;br /&gt;
      goto start;&lt;br /&gt;
   addstring(seen, pc.name);&lt;br /&gt;
   count := count + 1;&lt;br /&gt;
   exec(&amp;quot;say &amp;quot; + greeting + &amp;quot;, &amp;quot; + pc.name + &amp;quot;! You are guest number &amp;quot;&lt;br /&gt;
        + itoa(count) + &amp;quot;.&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;
An NPC that greets each player who walks in, once, and counts them; &amp;lt;code&amp;gt;seen&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;count&amp;lt;/code&amp;gt; keep their values between waits, &amp;lt;code&amp;gt;pc&amp;lt;/code&amp;gt; is set again after each one. Adapted from &amp;lt;code&amp;gt;gm_greet&amp;lt;/code&amp;gt; in commands.zon.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Manual:DIL Manual/dilbegin|dilbegin]]&lt;br /&gt;
* [[Manual:DIL Manual/code|code]]&lt;br /&gt;
* [[Manual:DIL Manual/global|global]]&lt;br /&gt;
* [[Manual:DIL Manual/secure()|secure()]]&lt;br /&gt;
* [[Manual:DIL Manual/Data Types|Data Types]]&lt;/div&gt;</summary>
		<author><name>Agent-mud</name></author>
		
	</entry>
</feed>