Difference between revisions of "Manual:DIL Manual/subextra()"
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: | ||
| + | = subextra() = | ||
| + | '''Procedure.''' Removes an extra description by name. | ||
| + | subextra(list : extraptr, name : string) | ||
| − | < | + | Removes the first extra in the list that has <code>name</code> as one of its names, ignoring case. The list is a unit's field: <code>u.extra</code>, <code>pc.quests</code> or <code>pc.info</code>. Only one extra goes per call. |
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | == Parameters == | |
| − | + | {| class="wikitable" | |
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | list || extraptr || The field <code>u.extra</code>, <code>pc.quests</code> or <code>pc.info</code>. | ||
| + | |- | ||
| + | | name || string || The name of the extra to remove. | ||
| + | |} | ||
| − | + | == Notes == | |
| − | + | * The first argument must be the field itself. An extraptr variable is refused by vmc: "Arg 1 of 'subextra' not a unit extra description". | |
| − | + | * The name must be a whole name of the extra: <code>"quest"</code> doesn't remove an extra named <code>"quest done"</code>. | |
| − | + | * When no extra matches, or the unit is null, nothing happens. | |
| − | + | * To remove every extra with the name, loop while <code>name in list</code>. | |
| + | * Don't rely on an extraptr variable that pointed at the removed extra; look the extra up again with <code>in</code> afterwards. | ||
| − | + | == Example == | |
| + | <pre> | ||
| + | dilbegin set_power(pwr : integer); | ||
| + | code | ||
| + | { | ||
| + | subextra(self.extra, "$power"); | ||
| + | addextra(self.extra, {"$power"}, itoa(pwr)); | ||
| + | return; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Keeps one hidden <code>$power</code> extra on the unit, replacing the old value. Adapted from barbarian.zon. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/addextra()|addextra()]] | ||
| + | * [[Manual:DIL Manual/extra|extra]] | ||
| + | * [[Manual:DIL Manual/quests|quests]] | ||
| + | * [[Manual:DIL Manual/info|info]] | ||
| + | * [[Manual:DIL Manual/in|in]] | ||
Latest revision as of 23:23, 14 November 2026
subextra()
Procedure. Removes an extra description by name.
subextra(list : extraptr, name : string)
Removes the first extra in the list that has name as one of its names, ignoring case. The list is a unit's field: u.extra, pc.quests or pc.info. Only one extra goes per call.
Parameters
| Name | Type | Meaning |
|---|---|---|
| list | extraptr | The field u.extra, pc.quests or pc.info.
|
| name | string | The name of the extra to remove. |
Notes
- The first argument must be the field itself. An extraptr variable is refused by vmc: "Arg 1 of 'subextra' not a unit extra description".
- The name must be a whole name of the extra:
"quest"doesn't remove an extra named"quest done". - When no extra matches, or the unit is null, nothing happens.
- To remove every extra with the name, loop while
name in list. - Don't rely on an extraptr variable that pointed at the removed extra; look the extra up again with
inafterwards.
Example
dilbegin set_power(pwr : integer);
code
{
subextra(self.extra, "$power");
addextra(self.extra, {"$power"}, itoa(pwr));
return;
}
dilend
Keeps one hidden $power extra on the unit, replacing the old value. Adapted from barbarian.zon.