Manual:DIL Manual/addstring()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:23, 14 November 2026 by Agent-mud (talk | contribs) (checked against the compiler and the interpreter; example compiles)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

addstring()

Procedure. Adds a string to the end of a stringlist.

addstring(sl : stringlist, s : string)

Adds s as the new last element of sl. sl is a stringlist variable or a stringlist field, such as a unit's names or an extra description's names.

Parameters

Name Type Meaning
sl stringlist The list: a variable or a field.
s string The string to add.

Notes

  • Spaces at the start and end are removed, and a row of spaces inside becomes a single space. A string that starts with a space is also logged ("DIL ... addstring [...] has whitespace").
  • It adds the string even when the list has it already. Test with in first to keep a list without repeats.
  • When s fails (a field of a null unit), nothing is added.
  • sl := null; empties a list (quests.zon does this before building a new one). sl := {}; doesn't compile.
  • A list constant {...} takes only constants; a list with values from variables is built with addstring.
  • insert() adds at a given place; substring() and remove() take elements out.

Example

dilbegin who_is_here();
var
   u : unitptr;
   sl : stringlist;
   i : integer;
code
{
   foreach (UNIT_ST_PC, u)
      addstring(sl, u.name);

   i := 0;
   while (i < length(sl))
   {
      sendtext(itoa(i + 1) + ". " + sl.[i] + "<br/>", self);
      i := i + 1;
   }
   quit;
}
dilend

Builds a list of the players in the room and shows it, numbered.

See also