<?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%2Fintlist</id>
	<title>Manual:DIL Manual/intlist - 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%2Fintlist"/>
	<link rel="alternate" type="text/html" href="https://wiki.dikumud.com/index.php?title=Manual:DIL_Manual/intlist&amp;action=history"/>
	<updated>2026-11-22T20:32:22Z</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/intlist&amp;diff=3134&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/intlist&amp;diff=3134&amp;oldid=prev"/>
		<updated>2026-11-14T23:27:47Z</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;= intlist =&lt;br /&gt;
'''Type.''' An ordered list of integers.&lt;br /&gt;
&lt;br /&gt;
 var&lt;br /&gt;
    il : intlist;&lt;br /&gt;
&lt;br /&gt;
An intlist keeps a row of numbers in one variable: a table to look values up in, or the numbers of an extra description (its &amp;lt;code&amp;gt;vals&amp;lt;/code&amp;gt;). A list is written as integer constants in braces: &amp;lt;code&amp;gt;{10, -3, 0x10, MAT_IRON}&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
An intlist variable holds its own list. Assigning a list to it copies the numbers, and a template that gets an intlist argument gets a copy as well.&lt;br /&gt;
&lt;br /&gt;
== Working with an intlist ==&lt;br /&gt;
* &amp;lt;code&amp;gt;il.[i]&amp;lt;/code&amp;gt; is the number at position &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt;, counting from 0. It can be assigned to: &amp;lt;code&amp;gt;il.[2] := 50;&amp;lt;/code&amp;gt;.&lt;br /&gt;
* &amp;lt;code&amp;gt;length(il)&amp;lt;/code&amp;gt; is the number of entries.&lt;br /&gt;
* &amp;lt;code&amp;gt;insert(il, i, n)&amp;lt;/code&amp;gt; puts &amp;lt;code&amp;gt;n&amp;lt;/code&amp;gt; in at position &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt;, moving the rest up; &amp;lt;code&amp;gt;insert(il, length(il), n)&amp;lt;/code&amp;gt; adds it at the end. &amp;lt;code&amp;gt;remove(il, i)&amp;lt;/code&amp;gt; takes position &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; out.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* The list doesn't grow by itself: reading &amp;lt;code&amp;gt;il.[i]&amp;lt;/code&amp;gt; outside it fails, and assigning outside it does nothing. Use &amp;lt;code&amp;gt;insert()&amp;lt;/code&amp;gt; to make it longer. (Older pages said that the gap is filled with zeros; it isn't.)&lt;br /&gt;
* &amp;lt;code&amp;gt;{...}&amp;lt;/code&amp;gt; may hold only constants: numbers, macros, and negative numbers. &amp;lt;code&amp;gt;il := {};&amp;lt;/code&amp;gt; doesn't compile (an empty &amp;lt;code&amp;gt;{}&amp;lt;/code&amp;gt; only works as an argument in a zone file's &amp;lt;code&amp;gt;dilcopy&amp;lt;/code&amp;gt;); &amp;lt;code&amp;gt;il := null;&amp;lt;/code&amp;gt; empties a list.&lt;br /&gt;
* There is no &amp;lt;code&amp;gt;in&amp;lt;/code&amp;gt; for intlists: walk the list to look for a number.&lt;br /&gt;
* Intlist variables keep their value through waits and are saved with the unit.&lt;br /&gt;
* An intlist can be the argument of a template copied with &amp;lt;code&amp;gt;dilcopy&amp;lt;/code&amp;gt; in a zone file, but not of the &amp;lt;code&amp;gt;dilcopy()&amp;lt;/code&amp;gt; procedure.&lt;br /&gt;
* The wiki also had this type under the name [[Manual:DIL Manual/integerlist|integerlist]]; the keyword is &amp;lt;code&amp;gt;intlist&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dilbegin integer roll_bonus();&lt;br /&gt;
var&lt;br /&gt;
   table : intlist;&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   // index 2..16 is the sum of 2d8; 0 and 1 are never used&lt;br /&gt;
   table := {0, 0, -3, -2, -2, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2, 2, 3};&lt;br /&gt;
   return (table.[rnd(1, 8) + rnd(1, 8)]);&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&lt;br /&gt;
dilbegin integer sum_list(il : intlist);&lt;br /&gt;
var&lt;br /&gt;
   i, sum : integer;&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   while (i &amp;lt; length(il))&lt;br /&gt;
   {&lt;br /&gt;
      sum := sum + il.[i];&lt;br /&gt;
      i := i + 1;&lt;br /&gt;
   }&lt;br /&gt;
   return (sum);&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&lt;br /&gt;
dilbegin grow_list();&lt;br /&gt;
external&lt;br /&gt;
   integer sum_list(il : intlist);&lt;br /&gt;
var&lt;br /&gt;
   il : intlist;&lt;br /&gt;
   n : integer;&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   il := {5, 10};&lt;br /&gt;
   insert(il, length(il), 20);   // append: il is now {5, 10, 20}&lt;br /&gt;
   il.[0] := 1;                  // {1, 10, 20}&lt;br /&gt;
   n := sum_list(il);&lt;br /&gt;
   log(&amp;quot;sum is &amp;quot; + itoa(n));     // sum is 31&lt;br /&gt;
   quit;&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A lookup table for a 2d8 roll (as the &amp;lt;code&amp;gt;roll8&amp;lt;/code&amp;gt; table in randomt.zon), a function that adds up a list, and a program that grows one.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Manual:DIL Manual/integer|integer]]&lt;br /&gt;
* [[Manual:DIL Manual/stringlist|stringlist]]&lt;br /&gt;
* [[Manual:DIL Manual/insert()|insert()]]&lt;br /&gt;
* [[Manual:DIL Manual/remove()|remove()]]&lt;br /&gt;
* [[Manual:DIL Manual/length()|length()]]&lt;br /&gt;
* [[Manual:DIL Manual/vals|vals]]&lt;br /&gt;
* [[Manual:DIL Manual/global|global]]&lt;/div&gt;</summary>
		<author><name>Agent-mud</name></author>
		
	</entry>
</feed>