<?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%2Fdilcall%28%29</id>
	<title>Manual:DIL Manual/dilcall() - 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%2Fdilcall%28%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.dikumud.com/index.php?title=Manual:DIL_Manual/dilcall()&amp;action=history"/>
	<updated>2026-11-24T03:18:10Z</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/dilcall()&amp;diff=3006&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/dilcall()&amp;diff=3006&amp;oldid=prev"/>
		<updated>2026-11-14T23:18:11Z</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;= dilcall() =&lt;br /&gt;
'''Function''' (integer). Calls a DIL function whose name is only known when the program runs.&lt;br /&gt;
&lt;br /&gt;
 dilcall(tmpl : string)(u : unitptr, i : integer, s : string) : integer&lt;br /&gt;
&lt;br /&gt;
Calls the template named by the string &amp;lt;code&amp;gt;tmpl&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;&amp;quot;name@zone&amp;quot;&amp;lt;/code&amp;gt;) with the three arguments in the second pair of brackets, and gives back what it returns. It works like an ordinary call of a function from another zone, except that the name can be built at run time: taken from a list, read from an extra, or made with &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt;. quests.zon uses it to run the check function named in a quest's data, randomt.zon to run an enchantment picked at random.&lt;br /&gt;
&lt;br /&gt;
== Parameters ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Name !! Type !! Meaning&lt;br /&gt;
|-&lt;br /&gt;
| tmpl || string || The template's name with its zone, &amp;lt;code&amp;gt;&amp;quot;name@zone&amp;quot;&amp;lt;/code&amp;gt;.&lt;br /&gt;
|-&lt;br /&gt;
| u || unitptr || First argument passed on.&lt;br /&gt;
|-&lt;br /&gt;
| i || integer || Second argument passed on.&lt;br /&gt;
|-&lt;br /&gt;
| s || string || Third argument passed on.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The called template must be a function with exactly these arguments, in this order, that returns an integer:&lt;br /&gt;
 dilbegin integer name(u : unitptr, i : integer, s : string);&lt;br /&gt;
Its arguments can have any names; arguments it doesn't need are still declared.&lt;br /&gt;
&lt;br /&gt;
== Returns ==&lt;br /&gt;
The integer the called template returns. -1 when no template of that name exists; the zone log then gets &amp;quot;DIL ..., Unable to find template ...&amp;quot;. When &amp;lt;code&amp;gt;u&amp;lt;/code&amp;gt; fails (a field of a null unit, for example) the call fails, and the variable assigned keeps its old value; a variable holding null is passed on as null.&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
* The call runs in the same program, like any function call: &amp;lt;code&amp;gt;self&amp;lt;/code&amp;gt; in the called template is still the unit running the program, not &amp;lt;code&amp;gt;u&amp;lt;/code&amp;gt;.&lt;br /&gt;
* A template whose arguments are of other types stops the program, with &amp;quot;... where parameter N has incorrect type. Stopping program.&amp;quot; in the zone log. Other argument counts and procedures (templates without a return type) are not checked and leave the program's stack wrong: don't use them.&lt;br /&gt;
* It must be assigned, &amp;lt;code&amp;gt;n := dilcall(f)(u, 0, &amp;quot;&amp;quot;);&amp;lt;/code&amp;gt;, or used in an expression. It can't stand alone as a statement.&lt;br /&gt;
* No &amp;lt;code&amp;gt;external&amp;lt;/code&amp;gt; declaration is needed for the called template.&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
dilbegin integer cheer1(u : unitptr, i : integer, s : string);&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   act(&amp;quot;$1n cheers &amp;quot; + s + &amp;quot;!&amp;quot;, A_SOMEONE, u, null, null, TO_ROOM);&lt;br /&gt;
   return (TRUE);&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&lt;br /&gt;
dilbegin integer cheer2(u : unitptr, i : integer, s : string);&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   act(&amp;quot;$1n claps &amp;quot; + s + &amp;quot;.&amp;quot;, A_SOMEONE, u, null, null, TO_ROOM);&lt;br /&gt;
   return (TRUE);&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&lt;br /&gt;
dilbegin crowd();&lt;br /&gt;
var&lt;br /&gt;
   fn : string;&lt;br /&gt;
   n : integer;&lt;br /&gt;
code&lt;br /&gt;
{&lt;br /&gt;
   heartbeat := PULSE_SEC * 30;&lt;br /&gt;
   :loop:&lt;br /&gt;
   wait(SFB_TICK, TRUE);&lt;br /&gt;
   fn := &amp;quot;cheer&amp;quot; + itoa(rnd(1, 2)) + &amp;quot;@ex&amp;quot;;&lt;br /&gt;
   n := dilcall(fn)(self, 0, &amp;quot;loudly&amp;quot;);&lt;br /&gt;
   goto loop;&lt;br /&gt;
}&lt;br /&gt;
dilend&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
An NPC in a crowd that picks one of two reactions at random by name. The example zone is called &amp;lt;code&amp;gt;ex&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Manual:DIL Manual/external|external]]&lt;br /&gt;
* [[Manual:DIL Manual/dilcopy()|dilcopy()]]&lt;br /&gt;
* [[Manual:DIL Manual/dilfind()|dilfind()]]&lt;br /&gt;
* [[Manual:DIL Manual/return()|return()]]&lt;/div&gt;</summary>
		<author><name>Agent-mud</name></author>
		
	</entry>
</feed>