Manual:DIL Manual/addstring()
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
infirst to keep a list without repeats. - When
sfails (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 withaddstring. insert()adds at a given place;substring()andremove()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.