Difference between revisions of "Manual:DIL Manual/addextra()"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the compiler and the interpreter; example compiles)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
= addextra() =
 +
'''Procedure.''' Adds an extra description to a unit's extras, quests or info.
  
 +
addextra(list : extraptr, names : stringlist, text : string)
 +
addextra(list : extraptr, names : stringlist, text : string, vals : intlist)
  
−
<span id="bpaddex"></span>
+
Makes a new extra description with the given names and text (and numbers, in the second form) and puts it first in the list. The list is a unit's field: <code>u.extra</code> on any unit, or <code>pc.quests</code> and <code>pc.info</code> on a player. Scripts often keep data in hidden extras whose names start with <code>$</code>, and a quest marks a player with an extra in <code>pc.quests</code>.
−
addextra ( var e : extraptr, l : stringlist , s : string )
 
−
    e : Extra description list to add element to.
 
−
    l : Stringlist for the .names field.
 
−
    s : String for the .descr field.
 
−
    result: Adds an extra description to a list of extra descriptions.
 
  
−
<strong>CAVEAT</strong> builder: You cannot use an extraptr variable as the e
+
== Parameters ==
−
argument, but you may continue to use the following form:
+
{| class="wikitable"
 +
! Name !! Type !! Meaning
 +
|-
 +
| list || extraptr || The field <code>u.extra</code>, <code>pc.quests</code> or <code>pc.info</code>.
 +
|-
 +
| names || stringlist || The names of the new extra (its <code>.names</code>); may be <code>null</code> for none.
 +
|-
 +
| text || string || Its text (<code>.descr</code>). <code>""</code> is fine.
 +
|-
 +
| vals || intlist || Optional: numbers for its <code>.vals</code>.
 +
|}
  
−
    ...
+
== Notes ==
−
    ...
+
* The first argument must be the field itself. An extraptr variable is refused by vmc: "Arg 1 of 'addextra' not a unit extra description".
−
    addextra (self.quests, "Bozo's Quest");
+
* An extra with the same name already there stays: the new one comes first and hides it from <code>in</code> and <code>u.extra.["name"]</code>. To replace an extra, <code>subextra()</code> it first.
−
    ...
+
* On a field of a null unit, or <code>pc.quests</code> or <code>pc.info</code> on something that isn't a player, nothing happens.
−
    ...
+
* <code>{...}</code> takes only constants. Names that come from variables go in a stringlist built with <code>addstring()</code>.
−
See also:
+
* For quests, use the functions in quests.zon (<code>qstSetOngoing@quests</code> and the others) rather than writing the extras by hand, so every quest looks the same in the <code>quests</code> command.
−
  subextra
+
 
 +
== Example ==
 +
<pre>
 +
dilbegin quest_finish(pc : unitptr, qon : string, qdone : string);
 +
var
 +
  sl : stringlist;
 +
code
 +
{
 +
  subextra(pc.quests, qon);
 +
  sl := null;
 +
  addstring(sl, qdone);
 +
  addextra(pc.quests, sl, "");
 +
  return;
 +
}
 +
dilend
 +
</pre>
 +
Swaps a player's "ongoing" quest entry for a "complete" one. Adapted from quests.zon.
 +
 
 +
== See also ==
 +
* [[Manual:DIL Manual/subextra()|subextra()]]
 +
* [[Manual:DIL Manual/extra|extra]]
 +
* [[Manual:DIL Manual/quests|quests]]
 +
* [[Manual:DIL Manual/info|info]]
 +
* [[Manual:DIL Manual/in|in]]
 +
* [[Manual:DIL Manual/extraptr|extraptr]]
 +
* [[Manual:DIL Manual/addstring()|addstring()]]

Latest revision as of 23:23, 14 November 2026

addextra()

Procedure. Adds an extra description to a unit's extras, quests or info.

addextra(list : extraptr, names : stringlist, text : string)
addextra(list : extraptr, names : stringlist, text : string, vals : intlist)

Makes a new extra description with the given names and text (and numbers, in the second form) and puts it first in the list. The list is a unit's field: u.extra on any unit, or pc.quests and pc.info on a player. Scripts often keep data in hidden extras whose names start with $, and a quest marks a player with an extra in pc.quests.

Parameters

Name Type Meaning
list extraptr The field u.extra, pc.quests or pc.info.
names stringlist The names of the new extra (its .names); may be null for none.
text string Its text (.descr). "" is fine.
vals intlist Optional: numbers for its .vals.

Notes

  • The first argument must be the field itself. An extraptr variable is refused by vmc: "Arg 1 of 'addextra' not a unit extra description".
  • An extra with the same name already there stays: the new one comes first and hides it from in and u.extra.["name"]. To replace an extra, subextra() it first.
  • On a field of a null unit, or pc.quests or pc.info on something that isn't a player, nothing happens.
  • {...} takes only constants. Names that come from variables go in a stringlist built with addstring().
  • For quests, use the functions in quests.zon (qstSetOngoing@quests and the others) rather than writing the extras by hand, so every quest looks the same in the quests command.

Example

dilbegin quest_finish(pc : unitptr, qon : string, qdone : string);
var
   sl : stringlist;
code
{
   subextra(pc.quests, qon);
   sl := null;
   addstring(sl, qdone);
   addextra(pc.quests, sl, "");
   return;
}
dilend

Swaps a player's "ongoing" quest entry for a "complete" one. Adapted from quests.zon.

See also