Difference between revisions of "Manual:DIL Manual/addextra()"
Jump to navigation
Jump to search
(checked against the compiler and the interpreter; example compiles) |
|||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| + | = addextra() = | ||
| + | '''Procedure.''' Adds an extra description to a unit's extras, quests or info. | ||
| + | addextra(list : extraptr, names : stringlist, text : string) | ||
| + | addextra(list : extraptr, names : stringlist, text : string, vals : intlist) | ||
| − | + | Makes a new extra description with the given names and text (and numbers, in the second form) and puts it first in the list. The list is a unit's field: <code>u.extra</code> on any unit, or <code>pc.quests</code> and <code>pc.info</code> on a player. Scripts often keep data in hidden extras whose names start with <code>$</code>, and a quest marks a player with an extra in <code>pc.quests</code>. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | list || extraptr || The field <code>u.extra</code>, <code>pc.quests</code> or <code>pc.info</code>. | ||
| + | |- | ||
| + | | names || stringlist || The names of the new extra (its <code>.names</code>); may be <code>null</code> for none. | ||
| + | |- | ||
| + | | text || string || Its text (<code>.descr</code>). <code>""</code> is fine. | ||
| + | |- | ||
| + | | vals || intlist || Optional: numbers for its <code>.vals</code>. | ||
| + | |} | ||
| − | + | == Notes == | |
| − | + | * The first argument must be the field itself. An extraptr variable is refused by vmc: "Arg 1 of 'addextra' not a unit extra description". | |
| − | + | * An extra with the same name already there stays: the new one comes first and hides it from <code>in</code> and <code>u.extra.["name"]</code>. To replace an extra, <code>subextra()</code> it first. | |
| − | + | * On a field of a null unit, or <code>pc.quests</code> or <code>pc.info</code> on something that isn't a player, nothing happens. | |
| − | + | * <code>{...}</code> takes only constants. Names that come from variables go in a stringlist built with <code>addstring()</code>. | |
| − | See also: | + | * For quests, use the functions in quests.zon (<code>qstSetOngoing@quests</code> and the others) rather than writing the extras by hand, so every quest looks the same in the <code>quests</code> command. |
| − | + | ||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin quest_finish(pc : unitptr, qon : string, qdone : string); | ||
| + | var | ||
| + | sl : stringlist; | ||
| + | code | ||
| + | { | ||
| + | subextra(pc.quests, qon); | ||
| + | sl := null; | ||
| + | addstring(sl, qdone); | ||
| + | addextra(pc.quests, sl, ""); | ||
| + | return; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Swaps a player's "ongoing" quest entry for a "complete" one. Adapted from quests.zon. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/subextra()|subextra()]] | ||
| + | * [[Manual:DIL Manual/extra|extra]] | ||
| + | * [[Manual:DIL Manual/quests|quests]] | ||
| + | * [[Manual:DIL Manual/info|info]] | ||
| + | * [[Manual:DIL Manual/in|in]] | ||
| + | * [[Manual:DIL Manual/extraptr|extraptr]] | ||
| + | * [[Manual:DIL Manual/addstring()|addstring()]] | ||
Latest revision as of 23:23, 14 November 2026
addextra()
Procedure. Adds an extra description to a unit's extras, quests or info.
addextra(list : extraptr, names : stringlist, text : string) addextra(list : extraptr, names : stringlist, text : string, vals : intlist)
Makes a new extra description with the given names and text (and numbers, in the second form) and puts it first in the list. The list is a unit's field: u.extra on any unit, or pc.quests and pc.info on a player. Scripts often keep data in hidden extras whose names start with $, and a quest marks a player with an extra in pc.quests.
Parameters
| Name | Type | Meaning |
|---|---|---|
| list | extraptr | The field u.extra, pc.quests or pc.info.
|
| names | stringlist | The names of the new extra (its .names); may be null for none.
|
| text | string | Its text (.descr). "" is fine.
|
| vals | intlist | Optional: numbers for its .vals.
|
Notes
- The first argument must be the field itself. An extraptr variable is refused by vmc: "Arg 1 of 'addextra' not a unit extra description".
- An extra with the same name already there stays: the new one comes first and hides it from
inandu.extra.["name"]. To replace an extra,subextra()it first. - On a field of a null unit, or
pc.questsorpc.infoon something that isn't a player, nothing happens. {...}takes only constants. Names that come from variables go in a stringlist built withaddstring().- For quests, use the functions in quests.zon (
qstSetOngoing@questsand the others) rather than writing the extras by hand, so every quest looks the same in thequestscommand.
Example
dilbegin quest_finish(pc : unitptr, qon : string, qdone : string);
var
sl : stringlist;
code
{
subextra(pc.quests, qon);
sl := null;
addstring(sl, qdone);
addextra(pc.quests, sl, "");
return;
}
dilend
Swaps a player's "ongoing" quest entry for a "complete" one. Adapted from quests.zon.