Difference between revisions of "Manual:DIL Manual/weapon name()"
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: | ||
| + | = weapon name() = | ||
| + | '''Function''' (string). Gives the name of a weapon type from its number. | ||
| + | weapon_name(i : integer) | ||
| − | < | + | The weapon numbers are the <code>WPN_</code> constants in <code>vme/include/values.h</code>, for example <code>WPN_DAGGER</code> (20). A weapon object's type is its <code>value[0]</code>. The names come from the <code>name</code> lines in <code>vme/etc/weapons.def</code>, in lower case: <code>weapon_name(WPN_DAGGER)</code> is "dagger". Numbers 0 to 6 are the weapon groups (<code>WPN_ROOT</code> to <code>WPN_SPECIAL</code> in <code>vme/include/vme.h</code>), with names like "category sword". |
| − | + | == Parameters == | |
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | i || integer || The weapon number. | ||
| + | |} | ||
| − | + | == Returns == | |
| − | + | The weapon's name; "" when the number is in range but has no weapon. Outside 0 to 199 (<code>WPN_TREE_MAX</code> - 1) it gives null. | |
| − | |||
| − | |||
| − | + | == Notes == | |
| − | + | * The null outside the range is how the weapons list in commands.zon finds the end: <code>while (weapon_name(i) != null)</code>. Assigned to a string variable, null makes it "". | |
| − | + | * Don't put a number that may be out of range straight into <code>+</code>: <code>"a " + weapon_name(i)</code> with a null makes an error that stops the program. [[Manual:DIL Manual/skill name()|skill name()]] gives "" instead and has no such trap. | |
| − | + | == Example == | |
| + | <pre> | ||
| + | dilbegin string weapon_kind(item : unitptr); | ||
| + | code | ||
| + | { | ||
| + | if (item.objecttype != ITEM_WEAPON) | ||
| + | return (""); | ||
| + | return (weapon_name(item.value[0])); | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | Gives the weapon type of an object, as the look code in baselook.zon does. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/skill name()|skill name()]] | |
| − | + | * [[Manual:DIL Manual/weapon info()|weapon info()]] | |
| + | * [[Manual:DIL Manual/weapons|weapons]] | ||
| + | * [[Manual:DIL Manual/value|value]] | ||
| + | * [[Manual:DIL Manual/objecttype|objecttype]] | ||
Latest revision as of 23:08, 14 November 2026
weapon name()
Function (string). Gives the name of a weapon type from its number.
weapon_name(i : integer)
The weapon numbers are the WPN_ constants in vme/include/values.h, for example WPN_DAGGER (20). A weapon object's type is its value[0]. The names come from the name lines in vme/etc/weapons.def, in lower case: weapon_name(WPN_DAGGER) is "dagger". Numbers 0 to 6 are the weapon groups (WPN_ROOT to WPN_SPECIAL in vme/include/vme.h), with names like "category sword".
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | The weapon number. |
Returns
The weapon's name; "" when the number is in range but has no weapon. Outside 0 to 199 (WPN_TREE_MAX - 1) it gives null.
Notes
- The null outside the range is how the weapons list in commands.zon finds the end:
while (weapon_name(i) != null). Assigned to a string variable, null makes it "". - Don't put a number that may be out of range straight into
+:"a " + weapon_name(i)with a null makes an error that stops the program. skill name() gives "" instead and has no such trap.
Example
dilbegin string weapon_kind(item : unitptr);
code
{
if (item.objecttype != ITEM_WEAPON)
return ("");
return (weapon_name(item.value[0]));
}
dilend
Gives the weapon type of an object, as the look code in baselook.zon does.