<?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%2Fglobal</id>
	<title>Manual:DIL Manual/global - 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%2Fglobal"/>
	<link rel="alternate" type="text/html" href="https://wiki.dikumud.com/index.php?title=Manual:DIL_Manual/global&amp;action=history"/>
	<updated>2026-11-23T22:05:51Z</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/global&amp;diff=3128&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/global&amp;diff=3128&amp;oldid=prev"/>
		<updated>2026-11-14T23:27:22Z</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;= global =&lt;br /&gt;
'''Keyword.''' Makes a variable shared by every program that names the same key.&lt;br /&gt;
&lt;br /&gt;
 var&lt;br /&gt;
    name : stringlist global key@zone;&lt;br /&gt;
    name : intlist global key@zone;&lt;br /&gt;
&lt;br /&gt;
A variable declared with &amp;lt;code&amp;gt;global key@zone&amp;lt;/code&amp;gt; is not the program's own: every variable in any template, in any zone, declared with the same key is the same list. A change made by one program is seen at once by all the others. The list lives in the server's memory from the first time a program uses the key until the server stops.&lt;br /&gt;
&lt;br /&gt;
The variable's own name is free; the key is what counts. randomt.zon fills its material tables once at boot (&amp;lt;code&amp;gt;constants@randomt&amp;lt;/code&amp;gt;, called from &amp;lt;code&amp;gt;initial_prg@basis&amp;lt;/code&amp;gt;) and its other templates read them, declaring only the ones they need.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* Use it for &amp;lt;code&amp;gt;stringlist&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;intlist&amp;lt;/code&amp;gt; only. vmc also accepts other types, but a global &amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt; is not shared (each program sees its own value), and an &amp;lt;code&amp;gt;integer&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;unitptr&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;extraptr&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;zoneptr&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;cmdptr&amp;lt;/code&amp;gt; global makes the server fail an assertion when the program starts.&lt;br /&gt;
* One name per line: &amp;lt;code&amp;gt;a, b : stringlist global key@zone;&amp;lt;/code&amp;gt; stops vmc with &amp;quot;var global cannot define multiple names&amp;quot;.&lt;br /&gt;
* The key needs both parts, &amp;lt;code&amp;gt;name@zone&amp;lt;/code&amp;gt;, or vmc says &amp;quot;var global missing name@zone&amp;quot;. The zone part is only part of the key: it doesn't have to be a real zone, but by habit it is the zone that owns the data.&lt;br /&gt;
* The key's case matters: &amp;lt;code&amp;gt;Guests@ex&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;guests@ex&amp;lt;/code&amp;gt; are two lists.&lt;br /&gt;
* All programs must agree on the type. A program that declares a key as an intlist when it already exists as a stringlist (or the other way) logs &amp;quot;DIL ERROR: getDilGlobalDilVar() type error&amp;quot; and gets a broken variable.&lt;br /&gt;
* Globals are never saved: they start empty at every boot, and a saved program doesn't store them. Fill them at boot (from &amp;lt;code&amp;gt;initial_prg@basis&amp;lt;/code&amp;gt;) or the first time they are needed (test &amp;lt;code&amp;gt;length(list) == 0&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Assigning to a global (&amp;lt;code&amp;gt;list := {...};&amp;lt;/code&amp;gt;), &amp;lt;code&amp;gt;addstring&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;substring&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;insert&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;remove&amp;lt;/code&amp;gt; all change the shared list.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dilbegin guestbook();&lt;br /&gt;
var&lt;br /&gt;
   guests : stringlist global guests@ex;&lt;br /&gt;
   pc : unitptr;&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));&lt;br /&gt;
   pc := activator;&lt;br /&gt;
   if (not (pc.name in guests))&lt;br /&gt;
      addstring(guests, pc.name);&lt;br /&gt;
   goto start;&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&lt;br /&gt;
dilbegin do_guests(arg : string);&lt;br /&gt;
var&lt;br /&gt;
   sl : stringlist global guests@ex;&lt;br /&gt;
   i : integer;&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   sendtext(&amp;quot;Guests since the last boot:&amp;lt;br/&amp;gt;&amp;quot;, self);&lt;br /&gt;
   while (i &amp;lt; length(sl))&lt;br /&gt;
   {&lt;br /&gt;
      sendtext(sl.[i] + &amp;quot;&amp;lt;br/&amp;gt;&amp;quot;, self);&lt;br /&gt;
      i := i + 1;&lt;br /&gt;
   }&lt;br /&gt;
   quit;&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;code&amp;gt;guestbook&amp;lt;/code&amp;gt;, on a room, notes every player who walks in; &amp;lt;code&amp;gt;do_guests&amp;lt;/code&amp;gt;, a command, lists them from the same global list.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Manual:DIL Manual/var|var]]&lt;br /&gt;
* [[Manual:DIL Manual/stringlist|stringlist]]&lt;br /&gt;
* [[Manual:DIL Manual/intlist|intlist]]&lt;br /&gt;
* [[Manual:DIL Manual/addstring()|addstring()]]&lt;br /&gt;
* [[Manual:DIL Manual/insert()|insert()]]&lt;/div&gt;</summary>
		<author><name>Agent-mud</name></author>
		
	</entry>
</feed>