Difference between revisions of "Manual:DIL Manual/Built-In Procedures"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(manual index generated from the checked keyword pages)
 
Line 1: Line 1:
−
<span id="biproc"></span>
+
A procedure does something and returns no value, so it is a statement of its own: <code>exec("say Hello", self);</code>. [[Manual:DIL Manual/cast spell()|cast_spell()]] can be called either way: see [[Manual:DIL Manual/Built-In Functions|Built-In Functions]].
−
<h3>Built-In Procedures:</h3>
 
−
    DIL features some built-in procedures that allows you increased control over
 
−
  in-game data structures and event handling. Once such procedure (used above)is
 
−
  'exec()'. The inline procedures are used as any other procedure by typing its
 
−
  name, followed by a list of argument expression enclosed in parentheses. The
 
−
  return types of the expressions used for built-in procedure calls are checked
 
−
  by the compiler.
 
  
−
    DIL also lets you call templates defined in the current or other zones. The
+
Each line gives the call with its arguments and what it does. Click a name for the full page. Statements such as <code>if</code>, <code>while</code> and <code>goto</code> are in [[Manual:DIL Manual/DIL Constructs|DIL Constructs]].
−
  naming of templates follows the normal naming convention for zone, using the
 
−
  'name@zone' as a symbolic name for a procedure. Before being able to use
 
−
  external procedures, you must define their name and type in a separate
 
−
  'external' section in the template. The declaration in the 'external' section
 
−
  should match the original declaration of the referenced program. You can define
 
−
  the number and type of arguments the template take, by listing them inside the
 
−
  declaration parenthesis (as well as in the original declaration of that template)
 
−
  (see example below)
 
  
−
'''Example:'''
+
__TOC__
  
−
<nowiki>
+
== Strings, lists and bits ==
 +
{| class="wikitable"
 +
! Procedure !! What it does
 +
|-
 +
| <code>[[Manual:DIL Manual/addstring()|addstring]](sl : stringlist, s : string)</code> || Adds a string to the end of a stringlist.
 +
|-
 +
| <code>[[Manual:DIL Manual/substring()|substring]](sl : stringlist, s : string)</code> || Removes a string from a stringlist.
 +
|-
 +
| <code>[[Manual:DIL Manual/insert()|insert]](list : stringlist or intlist, i : integer, value : string or integer)</code> || Puts a new entry into a stringlist or an intlist at a given position.
 +
|-
 +
| <code>[[Manual:DIL Manual/remove()|remove]](list : stringlist or intlist, i : integer)</code> || Takes the entry at a given position out of a stringlist or an intlist.
 +
|-
 +
| <code>[[Manual:DIL Manual/set()|set]](i : integer, bits : integer)</code> || Turns bits on in an integer variable or field.
 +
|-
 +
| <code>[[Manual:DIL Manual/unset()|unset]](i : integer, bits : integer)</code> || Turns bits off in an integer variable or field.
 +
|}
  
−
  dilbegin bar(s:string);
+
== Text to players ==
−
  code
+
{| class="wikitable"
−
dilend</nowiki>
+
! Procedure !! What it does
 +
|-
 +
| <code>[[Manual:DIL Manual/act()|act]](text : string, show : integer, char : unitptr, medium : unitptr or string, victim : unitptr or string, to : integer)</code> || Shows a message to the characters around someone, worded for each of them.
 +
|-
 +
| <code>[[Manual:DIL Manual/sendtext()|sendtext]](text : string, u : unitptr)</code> || Sends a text to one character's screen, exactly as it is.
 +
|-
 +
| <code>[[Manual:DIL Manual/pagestring()|pagestring]](s : string, u : unitptr)</code> || Sends a long text to a player, to be shown a page at a time.
 +
|-
 +
| <code>[[Manual:DIL Manual/beginedit()|beginedit]](pc : unitptr)</code> || Lets a player type several lines of text, which the program then gets.
 +
|-
 +
| <code>[[Manual:DIL Manual/killedit|killedit]](u : unitptr)</code> || Takes a player out of the text editor.
 +
|}
  
−
<nowiki>
+
== Messages between programs ==
 +
Messages are covered in [[Manual:DIL Manual/Messages|Messages]].
 +
{| class="wikitable"
 +
! Procedure !! What it does
 +
|-
 +
| <code>[[Manual:DIL Manual/send()|send]](msg : string)</code> || Sends a message to the DIL programs around the unit.
 +
|-
 +
| <code>[[Manual:DIL Manual/sendto()|sendto]](msg : string, u : unitptr)</code> || Sends a message to the DIL programs on one unit.
 +
|-
 +
| <code>[[Manual:DIL Manual/sendtoall()|sendtoall]](m : string, s : string)</code> || Sends a message to every copy of a unit in the game.
 +
|-
 +
| <code>[[Manual:DIL Manual/sendtoalldil()|sendtoalldil]](m : string, s : string)</code> || Sends a message to every running copy of a DIL template.
 +
|-
 +
| <code>[[Manual:DIL Manual/send done()|send_done]](cmd : string, activator : unitptr, medium : unitptr, target : unitptr, power : integer, arg : string, other : unitptr, auto : integer)</code> || Tells the programs around that a command has been carried out.
 +
|-
 +
| <code>[[Manual:DIL Manual/dispatch()|dispatch]](s : string)</code> || Sends a line to programs outside the game, such as the Discord bot.
 +
|}
  
−
  dilbegin foo();
+
== Waiting and events ==
−
  external
+
How a program waits for events and handles them.
−
    someproc@hades1();
+
{| class="wikitable"
−
    bar(s:string);
+
! Procedure !! What it does
−
  code
+
|-
−
dilend</nowiki>
+
| <code>[[Manual:DIL Manual/wait()|wait]](events : integer, condition)</code> || Stops the program until an event of the given kinds comes, for which a condition holds.
 +
|-
 +
| <code>[[Manual:DIL Manual/block|block]]</code> || Stops the event that woke the program from going any further.
 +
|-
 +
| <code>[[Manual:DIL Manual/priority|priority]]</code> || Keeps the unit's later programs from getting any event until <code>nopriority</code>.
 +
|-
 +
| <code>[[Manual:DIL Manual/nopriority|nopriority]]</code> || Ends the <code>priority</code> set by this program.
 +
|-
 +
| <code>[[Manual:DIL Manual/clear()|clear]](i : integer)</code> || Removes an interrupt set up with interrupt().
 +
|-
 +
| <code>[[Manual:DIL Manual/secure()|secure]](u : unitptr, label)</code> || Keeps a unit in a variable across waits, and names where to go when it leaves.
 +
|-
 +
| <code>[[Manual:DIL Manual/unsecure()|unsecure]](u : unitptr)</code> || Ends the secure on a unit.
 +
|-
 +
| <code>[[Manual:DIL Manual/quit|quit]]</code> || Ends the program for good.
 +
|}
  
−
    When the procedure is called, the argument expressions are calculated, and
+
== DIL programs ==
−
    passed to the template. Built-in procedures, their arguments and function
+
{| class="wikitable"
−
    are listed later.
+
! Procedure !! What it does
 +
|-
 +
| <code>[[Manual:DIL Manual/dilcopy()|dilcopy]](s : string, u : unitptr)</code> || Starts a copy of a DIL template on a unit.
 +
|}
  
−
    The following are definitions and documentation for the built-in procedures
+
== Moving and changing units ==
−
    in DIL. The definitions are not definitions 'as such', but serve to distinguish
+
{| class="wikitable"
−
    arguments in the documentation below.
+
! Procedure !! What it does
 +
|-
 +
| <code>[[Manual:DIL Manual/exec()|exec]](cmd : string, ch : unitptr)</code> || Makes a character carry out a command, as if they had typed it.
 +
|-
 +
| <code>[[Manual:DIL Manual/link()|link]](u : unitptr, into : unitptr)</code> || Moves a unit into another unit, with no checks and no messages.
 +
|-
 +
| <code>[[Manual:DIL Manual/destroy()|destroy]](u : unitptr)</code> || Removes a unit from the game.
 +
|-
 +
| <code>[[Manual:DIL Manual/store()|store]](u : unitptr, filename : string, container : integer)</code> || Saves a unit, or what is inside it, to a file.
 +
|-
 +
| <code>[[Manual:DIL Manual/follow()|follow]](ch : unitptr, leader : unitptr)</code> || Makes one character follow another, or stop following.
 +
|-
 +
| <code>[[Manual:DIL Manual/setbright()|setbright]](u : unitptr, light : integer)</code> || Sets how much light a unit gives.
 +
|-
 +
| <code>[[Manual:DIL Manual/set weight|set_weight]](u : unitptr, weight : integer)</code> || Sets a unit's total weight.
 +
|-
 +
| <code>[[Manual:DIL Manual/set weight base|set_weight_base]](u : unitptr, weight : integer)</code> || Sets a unit's own weight.
 +
|-
 +
| <code>[[Manual:DIL Manual/addextra()|addextra]](list : extraptr, names : stringlist, text : string)</code><br><code>addextra(list : extraptr, names : stringlist, text : string, vals : intlist)</code> || Adds an extra description to a unit's extras, quests or info.
 +
|-
 +
| <code>[[Manual:DIL Manual/subextra()|subextra]](list : extraptr, name : string)</code> || Removes an extra description by name.
 +
|-
 +
| <code>[[Manual:DIL Manual/addaff()|addaff]](u : unitptr, id : integer, duration : integer, beat : integer, data0 : integer, data1 : integer, data2 : integer, tif_first : integer, tif_tick : integer, tif_last : integer, apf : integer)</code> || Adds an affect to a unit.
 +
|-
 +
| <code>[[Manual:DIL Manual/subaff()|subaff]](u : unitptr, id : integer)</code> || Removes an affect from a unit.
 +
|-
 +
| <code>[[Manual:DIL Manual/addequip()|addequip]](u : unitptr, pos : integer)</code> || Puts an object a character carries on, at a given position.
 +
|-
 +
| <code>[[Manual:DIL Manual/unequip()|unequip]](u : unitptr)</code> || Takes off an object a character is wearing.
 +
|-
 +
| <code>[[Manual:DIL Manual/setroomexit()|setroomexit]](room : unitptr, dir : integer, toroom : unitptr)</code> || Points a room's exit in one direction at another room, making the exit if the room has none that way.
 +
|-
 +
| <code>[[Manual:DIL Manual/zonereset()|zonereset]](z : zoneptr)</code> || Resets a zone now.
 +
|}
  
 +
== Characters and combat ==
 +
{| class="wikitable"
 +
! Procedure !! What it does
 +
|-
 +
| <code>[[Manual:DIL Manual/set fighting()|set_fighting]](u : unitptr, t : unitptr)</code> || Starts a fight between two characters.
 +
|-
 +
| <code>[[Manual:DIL Manual/stop fighting()|stop_fighting]](u : unitptr, t : unitptr)</code> || Ends a character's fight with one opponent, or with all.
 +
|-
 +
| <code>[[Manual:DIL Manual/change speed()|change_speed]](u : unitptr, delay : integer)</code> || Delays a fighting character's next attacks.
 +
|-
 +
| <code>[[Manual:DIL Manual/position update()|position_update]](u : unitptr)</code> || Sets a character's position from its hit points, and kills it at -11 or below.
 +
|-
 +
| <code>[[Manual:DIL Manual/experience()|experience]](amount : integer, pc : unitptr)</code> || Gives a player experience points, or takes them away.
 +
|-
 +
| <code>[[Manual:DIL Manual/logcrime()|logcrime]](criminal : unitptr, victim : unitptr, crime : integer)</code> || Reports a crime to the justice system: who did it, to whom, and what.
 +
|}
  
−
---~---~---~---~---~---~---~---~---
+
== Players and the server ==
−
<span id="biproc"></span>
+
All of these except [[Manual:DIL Manual/gamestate()|gamestate()]] and [[Manual:DIL Manual/log()|log()]] work only in a zone with access level 0.
−
<h3>Built-In Procedures:</h3>
+
{| class="wikitable"
−
    DIL features some built-in procedures that allows you increased control over
+
! Procedure !! What it does
−
  in-game data structures and event handling. Once such procedure (used above)is
+
|-
−
  'exec()'. The inline procedures are used as any other procedure by typing its
+
| <code>[[Manual:DIL Manual/acc modify()|acc_modify]](pc : unitptr, amount : integer)</code> || Pays money into a player's account or takes it out.
−
  name, followed by a list of argument expression enclosed in parentheses. The
+
|-
−
  return types of the expressions used for built-in procedure calls are checked
+
| <code>[[Manual:DIL Manual/gamestate()|gamestate]](pc : unitptr, gs : integer)</code> || Takes a player out of the game to the menu, back into the game, or out altogether.
−
  by the compiler.
+
|-
 +
| <code>[[Manual:DIL Manual/set password()|set_password]](pc : unitptr, pwd : string)</code> || Sets a player's password.
 +
|-
 +
| <code>[[Manual:DIL Manual/delete player()|delete_player]](pname : string)</code> || Deletes a player character for good.
 +
|-
 +
| <code>[[Manual:DIL Manual/reset level()|reset_level]](pc : unitptr)</code> || Sets a mortal player's level back to 1.
 +
|-
 +
| <code>[[Manual:DIL Manual/reset vlevel()|reset_vlevel]](pc : unitptr)</code> || Sets a mortal player's virtual level back to 1.
 +
|-
 +
| <code>[[Manual:DIL Manual/reset race()|reset_race]](pc : unitptr)</code> || Rolls a player's body again from the race's values: weight, height, lifespan and age.
 +
|-
 +
| <code>[[Manual:DIL Manual/log()|log]](s : string)</code> || Writes a line to the server log.
 +
|-
 +
| <code>[[Manual:DIL Manual/reboot|reboot]](code : integer)</code> || Shuts the game server down.
 +
|}
  
−
    DIL also lets you call templates defined in the current or other zones.  The
+
== See also ==
−
  naming of templates follows the normal naming convention for zone, using the
+
* [[Manual:DIL Manual/Built-In Functions|Built-In Functions]]
−
  'name@zone' as a symbolic name for a procedure.  Before being able to use
+
* [[Manual:DIL Manual/DIL Constructs|DIL Constructs]]
−
  external procedures, you must define their name and type in a separate
+
* [[Manual:DIL Manual/Messages|Messages]]
−
  'external' section in the template.  The declaration in the 'external' section
 
−
  should match the original declaration of the referenced program. You can define
 
−
  the number and type of arguments the template take, by listing them inside the
 
−
  declaration parenthesis (as well as in the original declaration of that template)
 
−
  (see example below)
 
−
 
 
−
'''Example:'''
 
−
 
 
−
<nowiki>
 
−
 
 
−
  dilbegin bar(s:string);
 
−
  code
 
−
dilend</nowiki>
 
−
 
 
−
<nowiki>
 
−
 
 
−
  dilbegin foo();
 
−
  external
 
−
    someproc@hades1();
 
−
    bar(s:string);
 
−
  code
 
−
dilend</nowiki>
 
−
 
 
−
    When the procedure is called, the argument expressions are calculated, and
 
−
    passed to the template.  Built-in procedures, their arguments and function
 
−
    are listed later.
 
−
 
 
−
    The following are definitions and documentation for the built-in procedures
 
−
    in DIL. The definitions are not definitions 'as such', but serve to distinguish
 
−
    arguments in the documentation below.
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 

Latest revision as of 23:40, 14 November 2026

A procedure does something and returns no value, so it is a statement of its own: exec("say Hello", self);. cast_spell() can be called either way: see Built-In Functions.

Each line gives the call with its arguments and what it does. Click a name for the full page. Statements such as if, while and goto are in DIL Constructs.

Strings, lists and bits

Procedure What it does
addstring(sl : stringlist, s : string) Adds a string to the end of a stringlist.
substring(sl : stringlist, s : string) Removes a string from a stringlist.
insert(list : stringlist or intlist, i : integer, value : string or integer) Puts a new entry into a stringlist or an intlist at a given position.
remove(list : stringlist or intlist, i : integer) Takes the entry at a given position out of a stringlist or an intlist.
set(i : integer, bits : integer) Turns bits on in an integer variable or field.
unset(i : integer, bits : integer) Turns bits off in an integer variable or field.

Text to players

Procedure What it does
act(text : string, show : integer, char : unitptr, medium : unitptr or string, victim : unitptr or string, to : integer) Shows a message to the characters around someone, worded for each of them.
sendtext(text : string, u : unitptr) Sends a text to one character's screen, exactly as it is.
pagestring(s : string, u : unitptr) Sends a long text to a player, to be shown a page at a time.
beginedit(pc : unitptr) Lets a player type several lines of text, which the program then gets.
killedit(u : unitptr) Takes a player out of the text editor.

Messages between programs

Messages are covered in Messages.

Procedure What it does
send(msg : string) Sends a message to the DIL programs around the unit.
sendto(msg : string, u : unitptr) Sends a message to the DIL programs on one unit.
sendtoall(m : string, s : string) Sends a message to every copy of a unit in the game.
sendtoalldil(m : string, s : string) Sends a message to every running copy of a DIL template.
send_done(cmd : string, activator : unitptr, medium : unitptr, target : unitptr, power : integer, arg : string, other : unitptr, auto : integer) Tells the programs around that a command has been carried out.
dispatch(s : string) Sends a line to programs outside the game, such as the Discord bot.

Waiting and events

How a program waits for events and handles them.

Procedure What it does
wait(events : integer, condition) Stops the program until an event of the given kinds comes, for which a condition holds.
block Stops the event that woke the program from going any further.
priority Keeps the unit's later programs from getting any event until nopriority.
nopriority Ends the priority set by this program.
clear(i : integer) Removes an interrupt set up with interrupt().
secure(u : unitptr, label) Keeps a unit in a variable across waits, and names where to go when it leaves.
unsecure(u : unitptr) Ends the secure on a unit.
quit Ends the program for good.

DIL programs

Procedure What it does
dilcopy(s : string, u : unitptr) Starts a copy of a DIL template on a unit.

Moving and changing units

Procedure What it does
exec(cmd : string, ch : unitptr) Makes a character carry out a command, as if they had typed it.
link(u : unitptr, into : unitptr) Moves a unit into another unit, with no checks and no messages.
destroy(u : unitptr) Removes a unit from the game.
store(u : unitptr, filename : string, container : integer) Saves a unit, or what is inside it, to a file.
follow(ch : unitptr, leader : unitptr) Makes one character follow another, or stop following.
setbright(u : unitptr, light : integer) Sets how much light a unit gives.
set_weight(u : unitptr, weight : integer) Sets a unit's total weight.
set_weight_base(u : unitptr, weight : integer) Sets a unit's own weight.
addextra(list : extraptr, names : stringlist, text : string)
addextra(list : extraptr, names : stringlist, text : string, vals : intlist)
Adds an extra description to a unit's extras, quests or info.
subextra(list : extraptr, name : string) Removes an extra description by name.
addaff(u : unitptr, id : integer, duration : integer, beat : integer, data0 : integer, data1 : integer, data2 : integer, tif_first : integer, tif_tick : integer, tif_last : integer, apf : integer) Adds an affect to a unit.
subaff(u : unitptr, id : integer) Removes an affect from a unit.
addequip(u : unitptr, pos : integer) Puts an object a character carries on, at a given position.
unequip(u : unitptr) Takes off an object a character is wearing.
setroomexit(room : unitptr, dir : integer, toroom : unitptr) Points a room's exit in one direction at another room, making the exit if the room has none that way.
zonereset(z : zoneptr) Resets a zone now.

Characters and combat

Procedure What it does
set_fighting(u : unitptr, t : unitptr) Starts a fight between two characters.
stop_fighting(u : unitptr, t : unitptr) Ends a character's fight with one opponent, or with all.
change_speed(u : unitptr, delay : integer) Delays a fighting character's next attacks.
position_update(u : unitptr) Sets a character's position from its hit points, and kills it at -11 or below.
experience(amount : integer, pc : unitptr) Gives a player experience points, or takes them away.
logcrime(criminal : unitptr, victim : unitptr, crime : integer) Reports a crime to the justice system: who did it, to whom, and what.

Players and the server

All of these except gamestate() and log() work only in a zone with access level 0.

Procedure What it does
acc_modify(pc : unitptr, amount : integer) Pays money into a player's account or takes it out.
gamestate(pc : unitptr, gs : integer) Takes a player out of the game to the menu, back into the game, or out altogether.
set_password(pc : unitptr, pwd : string) Sets a player's password.
delete_player(pname : string) Deletes a player character for good.
reset_level(pc : unitptr) Sets a mortal player's level back to 1.
reset_vlevel(pc : unitptr) Sets a mortal player's virtual level back to 1.
reset_race(pc : unitptr) Rolls a player's body again from the race's values: weight, height, lifespan and age.
log(s : string) Writes a line to the server log.
reboot(code : integer) Shuts the game server down.

See also