Manual:DIL Manual/remove()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 23:20, 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

remove()

Procedure. Takes the entry at a given position out of a stringlist or an intlist.

remove(list : stringlist or intlist, i : integer)

The entries after it move down one place, so no gap is left. Positions count from 0. It works on a list variable and on the list fields of an extra (ex.names, ex.vals). To take a string out by its text rather than its position, use substring().

Parameters

Name Type Meaning
list stringlist or intlist The list to change: a variable or a list field, not a function's result.
i integer The position of the entry to remove.

Notes

  • A position below 0 or past the end does nothing.
  • When i is a failed value (a field of null), entry 0 is removed.
  • In an extra's names the first entry is the extra's own name, the one
 in finds it by: start removing data at position 1.
  • While removing several entries in a loop, go from the end to the start, or each removal
 shifts the positions still to come.

Example

dilbegin drop_entry(u : unitptr, cname : string);
var
   ex : extraptr;
   i : integer;
code
{
   ex := "$comp" in u.extra;
   if (ex == null)
      return;

   i := length(ex.names) - 1;
   while (i >= 1)
   {
      if (ex.names.[i] == cname)
      {
         remove(ex.names, i);
         remove(ex.vals, i);
      }
      i := i - 1;
   }
   return;
}
dilend

Takes a competition out of the names and values a player's extra keeps side by side, as competition.zon does.

See also