Difference between revisions of "Has"
(Created page with "The '''has''' command returns TRUE if the specified inventory item is in the player's inventory (i.e. the item's room number equals 255). == Syntax...") |
m (→Example) |
||
Line 24: | Line 24: | ||
<div class="CodeBlockHeader">Code:</div> | <div class="CodeBlockHeader">Code:</div> | ||
<syntaxhighlight lang="agi"> | <syntaxhighlight lang="agi"> | ||
− | if(has(i12)) { | + | if(has(i12)) |
+ | { | ||
print("you already have item 12"); | print("you already have item 12"); | ||
− | } | + | } |
[ equivalent code: | [ equivalent code: | ||
v50 = 255; | v50 = 255; | ||
− | if obj.in.room(i12, v50)) { | + | if obj.in.room(i12, v50)) |
+ | { | ||
print("you already have item 12"); | print("you already have item 12"); | ||
− | } | + | } |
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 12:03, 14 April 2019
The has command returns TRUE if the specified inventory item is in the player's inventory (i.e. the item's room number equals 255).
Syntax
has(itm iA)
has("item")
Remarks
Test commands are only valid in an if
statement.
The has command checks the room number value of item iA and returns true if it equals 255. This is basically a shortcut equivalent to the obj.in.room command if testing for room 255.
If an inventory item's room number is 255 it means the object has been 'picked up' and is in the player's inventory.
This statement can be combined with the NOT
operator to create a ‘not in inventory’ test.
Possible Errors
If the inventory item is not valid (the number exceeds the total number of inventory items in the OBJECT file), AGI will raise trappable error #23.
Example
<syntaxhighlight lang="agi"> if(has(i12))
{ print("you already have item 12"); }
[ equivalent code: v50 = 255; if obj.in.room(i12, v50))
{ print("you already have item 12"); }
</syntaxhighlight>
Technical Information
Required Interpreter Version: | Available in all AGI versions. |
Byte-Code Value: | 9 (0x09 hex) |