Contents Up Previous Next

Inventory item functions and properties

GetAtScreenXY (inventory)
GetProperty (inventory)
GetTextProperty (inventory)
IsInteractionAvailable (inventory)
RunInteraction (inventory)
Graphic property (inventory)
ID property (inventory)
Name property (inventory)


GetAtScreenXY (inventory)

(Formerly known as global function GetInvAt, which is now obsolete)

static InventoryItem* InventoryItem.GetAtScreenXY(int x, int y)
Returns the inventory item at SCREEN co-ordinates (X,Y). Note that this only detects inventory items on custom Inventory windows (that are switched on when this function is called), and is intended to allow you to do Verb Coin style GUIs and so on.

If there is no inventory item there, or if invalid co-ordinates are specified, returns null.

NOTE: The co-ordinates are SCREEN co-ordinates, NOT ROOM co-ordinates. This means that with a scrolling room, the co-ordinates you pass are relative to the screen's current position, and NOT absolute room co-ordinates. This means that this function is suitable for use with the mouse cursor position variables.

Example:

InventoryItem *item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
if (item == null) {
  Display("No inventory item at the mouse co-ordinates");
}
else {
  Display("Inventory item number %d at the mouse.", item.ID);
}
will display the number of the inv item that the mouse is over

See Also: InventoryItem.Name, Game.GetLocationName


GetProperty (inventory)

(Formerly known as GetInvProperty, which is now obsolete)

InventoryItem.GetProperty(string property)
Returns the custom property setting PROPERTY for the inventory item.

This command works with Number properties (it returns the number), and with Boolean properties (returns 1 if the box was checked, 0 if not).

Use the equivalent GetTextProperty function to get a text property.

Example:

if (inventory[1].GetProperty("Value") > 200)
  Display("Inventory item 1's value is over 200!");
will print the message if inventory item 1 has its "Value" property set to more than 200.

See Also: InventoryItem.GetTextProperty


GetTextProperty (inventory)

(Formerly known as GetInvPropertyText, which is now obsolete)
(Formerly known as InventoryItem.GetPropertyText, which is now obsolete)

String InventoryItem.GetTextProperty(string property)
Returns the custom property setting PROPERTY for the inventory item.

This command works with Text properties only. The property's text will be returned from this function.

Use the equivalent GetProperty function to get a non-text property.

Example:

String description = inventory[2].GetTextProperty("Description");
Display("Inv item 2's description: %s", description);
will retrieve inv item 2's "description" property and display it.

See Also: InventoryItem.GetProperty


IsInteractionAvailable (inventory)

(Formerly known as IsInventoryInteractionAvailable, which is now obsolete)

InventoryItem.IsInteractionAvailable(CursorMode)
Checks whether there is an interaction defined for activating the inventory item in cursor mode MODE.

This function is very similar to RunInteraction, except that rather than carry out any interactions it encounters, it simply returns 1 if something would have happened, or 0 if unhandled_event would have been run.

This is useful for enabling options on a verb-coin style GUI, for example.

Example:

if (iKeyring.IsInteractionAvailable(eModeLook) == 0)
  Display("looking at this item would not do anything.");
See Also: IsInteractionAvailable, InventoryItem.RunInteraction


RunInteraction (inventory)

(Formerly known as RunInventoryInteraction, which is now obsolete)

InventoryItem.RunInteraction(CursorMode)
Processes the interaction list as if the player had clicked the mouse on the inventory item, using the specified cursor mode.

Example:

if (button == eMouseLeftInv)
  inventory[game.inv_activated].RunInteraction(mouse.Mode);
will run the inventory interaction for the current cursor mode when the player clicks on the item (Handle Inv Clicks needs to be enabled for this to work)

See Also: InventoryItem.IsInteractionAvailable, ProcessClick, Character.RunInteraction


Graphic property (inventory)

(Formerly known as GetInvGraphic, which is now obsolete)
(Formerly known as SetInvItemPic, which is now obsolete)

int InventoryItem.Graphic
Gets/sets the sprite slot number of the inventory item. You could use this with the Object.Graphic property as a means of the player 'dropping' an inventory item, or it may be useful if you want to do a Raw Drawn inventory window.

Example:

int slot = player.ActiveInventory.Graphic;
will place the sprite number of the player's current inventory item into slot.

See Also: InventoryItem.GetAtScreenXY, InventoryItem.Name


ID property (inventory)

readonly int InventoryItem.ID
Gets the inventory item's ID number. This is the item's number from the editor, and is useful with commands such as Character.AddInventory which require an inventory number to add.

Example:

AddInventory(EGO, iShovel.ID);
uses the obsolete AddInventory command to add the shovel to EGO's inventory

See Also: Character.AddInventory, Character.LoseInventory


Name property (inventory)

(Formerly known as GetInvName, which is now obsolete)
(Formerly known as SetInvItemName, which is now obsolete)
(Formerly known as InventoryItem.GetName, which is now obsolete)
(Formerly known as InventoryItem.SetName, which is now obsolete)

String InventoryItem.Name;
Gets/sets the name of the inventory item. This is the name which is initially set under the Game tab, Inventory mode of the AGS Editor.

You can change this property if for example you want to change a 'bowl' to a 'bowl with water in' but want to use the same inventory item for it.

Note that the maximum length for the name of an inventory item is 24 characters - if the name you set is longer than this, it will be truncated.

Example:

Display("Active inventory: %s", player.ActiveInventory.Name);
will display the name of the player's current inventory item.

See Also: InventoryItem.GetAtScreenXY, InventoryItem.Graphic, Game.GetLocationName