Difference between revisions of "Manual:DIL Manual/remove()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
| + | = 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 (<code>ex.names</code>, | ||
| + | <code>ex.vals</code>). To take a string out by its text rather than its position, use | ||
| + | [[Manual:DIL Manual/substring()|substring()]]. | ||
| − | + | == Parameters == | |
| + | {| class="wikitable" | ||
| + | ! 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 <code>i</code> is a failed value (a field of null), entry 0 is removed. | |
| − | + | * In an extra's <code>names</code> the first entry is the extra's own name, the one | |
| + | <code>in</code> 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 == | |
| − | + | <pre> | |
| − | + | 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 | ||
| + | </pre> | ||
| + | Takes a competition out of the names and values a player's extra keeps side by side, as | ||
| + | competition.zon does. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/insert()|insert()]] | ||
| + | * [[Manual:DIL Manual/substring()|substring()]] | ||
| + | * [[Manual:DIL Manual/addstring()|addstring()]] | ||
| + | * [[Manual:DIL Manual/length()|length()]] | ||
| + | * [[Manual:DIL Manual/vals|vals]] | ||
Latest revision as of 23:20, 14 November 2026
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
iis a failed value (a field of null), entry 0 is removed. - In an extra's
namesthe 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.