Difference between revisions of "Manual:DIL Manual/extraptr"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = extraptr = | |
| − | + | '''Type.''' A pointer to an extra description. | |
| − | + | var | |
| − | + | exd : extraptr; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | Extra descriptions are the texts a unit shows when looked at (<code>look at sign</code>), and DIL also uses them to store data on units: quest flags, counters, settings. <code>look</code> doesn't show an extra whose first name starts with <code>$</code>, so such names hold data. Each extra has these fields: | |
| − | + | {| class="wikitable" | |
| − | + | ! Field !! Type !! Meaning | |
| + | |- | ||
| + | | [[Manual:DIL Manual/names|names]] || stringlist || the names it is found by | ||
| + | |- | ||
| + | | [[Manual:DIL Manual/name|name]] || string || the first of the names | ||
| + | |- | ||
| + | | [[Manual:DIL Manual/descr|descr]] || string || its text (read and write) | ||
| + | |- | ||
| + | | [[Manual:DIL Manual/vals|vals]] || intlist || numbers stored with it | ||
| + | |- | ||
| + | | [[Manual:DIL Manual/next|next]] || extraptr || the next extra on the same unit | ||
| + | |} | ||
| − | + | <code>u.extra</code> is the first extra of a unit. To find one by name, use <code>"name" in u.extra</code> or <code>u.extra.["name"]</code>; both give null when there is none. | |
| − | |||
| − | |||
| − | |||
| − | + | == Notes == | |
| − | < | + | * '''An extraptr variable is cleared at every wait''' (<code>wait</code>, <code>pause</code>, a heartbeat), and it can't be secured. Look the extra up again after waiting. |
| − | + | * A field of a null extraptr fails; test <code>exd == null</code> first. | |
| + | * <code>addextra()</code> and <code>subextra()</code> add and remove extras. An extra made with empty text is not added. | ||
| + | * Extras themselves are saved with the unit; extraptr variables are not (they come back null). | ||
| − | + | == Example == | |
| − | + | <pre> | |
| − | + | dilbegin visit_count(); | |
| − | + | var | |
| − | + | pc : unitptr; | |
| − | + | exd : extraptr; | |
| − | + | code | |
| + | { | ||
| + | :start: | ||
| + | wait(SFB_DONE, command(CMD_AUTO_ENTER) and (activator.type == UNIT_ST_PC) | ||
| + | and (activator.outside == self)); | ||
| + | pc := activator; | ||
| + | exd := "$visits" in pc.extra; | ||
| + | if (exd == null) | ||
| + | { | ||
| + | addextra(pc.extra, {"$visits"}, "1"); | ||
| + | sendtext("Welcome, stranger.<br/>", pc); | ||
| + | } | ||
| + | else | ||
| + | { | ||
| + | exd.descr := itoa(atoi(exd.descr) + 1); | ||
| + | sendtext("Welcome back, visit number " + exd.descr + ".<br/>", pc); | ||
| + | } | ||
| + | goto start; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | On a room: counts each player's visits in a hidden extra on the player. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/extra|extra]] | |
| − | + | * [[Manual:DIL Manual/addextra()|addextra()]] | |
| − | + | * [[Manual:DIL Manual/subextra()|subextra()]] | |
| − | + | * [[Manual:DIL Manual/in|in]] | |
| − | + | * [[Manual:DIL Manual/descr|descr]] | |
| − | + | * [[Manual:DIL Manual/vals|vals]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 23:27, 14 November 2026
Contents
extraptr
Type. A pointer to an extra description.
var exd : extraptr;
Extra descriptions are the texts a unit shows when looked at (look at sign), and DIL also uses them to store data on units: quest flags, counters, settings. look doesn't show an extra whose first name starts with $, so such names hold data. Each extra has these fields:
| Field | Type | Meaning |
|---|---|---|
| names | stringlist | the names it is found by |
| name | string | the first of the names |
| descr | string | its text (read and write) |
| vals | intlist | numbers stored with it |
| next | extraptr | the next extra on the same unit |
u.extra is the first extra of a unit. To find one by name, use "name" in u.extra or u.extra.["name"]; both give null when there is none.
Notes
- An extraptr variable is cleared at every wait (
wait,pause, a heartbeat), and it can't be secured. Look the extra up again after waiting. - A field of a null extraptr fails; test
exd == nullfirst. addextra()andsubextra()add and remove extras. An extra made with empty text is not added.- Extras themselves are saved with the unit; extraptr variables are not (they come back null).
Example
dilbegin visit_count();
var
pc : unitptr;
exd : extraptr;
code
{
:start:
wait(SFB_DONE, command(CMD_AUTO_ENTER) and (activator.type == UNIT_ST_PC)
and (activator.outside == self));
pc := activator;
exd := "$visits" in pc.extra;
if (exd == null)
{
addextra(pc.extra, {"$visits"}, "1");
sendtext("Welcome, stranger.<br/>", pc);
}
else
{
exd.descr := itoa(atoi(exd.descr) + 1);
sendtext("Welcome back, visit number " + exd.descr + ".<br/>", pc);
}
goto start;
}
dilend
On a room: counts each player's visits in a hidden extra on the player.