Skip to content

IInventory

Carenalga edited this page Feb 6, 2023 · 3 revisions

Description

Use it to handle the inventory. Is the shortcut for IInventory.gd, and can be used (from any script) with I (E.g. I.add_item('Card')).

Some things you can do with it:

  • Add and remove items in the inventory.
  • Make the cursor take the appeareance of an inventory item.
  • Know when an item has been added or removed.

Examples

# Adds the "Key" item to the inventory and makes it the current selected item (this changes the cursor)
I.add_item_as_active('Key')
I.remove_item('Card')
# Call the "_say_something" method once an item is added to the inventory
I.connect('item_add_done', self, '_say_something')

⬇️ Since version 1.9.0 ⬇️

# Add the DeckOfCards item to the inventory. Out of an E.run([])
I.DeckOfCards.add_now(false)
# Add the Key item to the inventory and make it the selected item. Inside an E.run([])
I.Key.add_as_active()
# Remove the Card item from the inventory. Inside an E.run([])
I.Card.remove()

Properties

Signals

  • inventory_show_requested( float time ). Emitted when show_inventory() is called. Inventory.gd connects to this signal in order to show and hide itself.

  • inventory_shown. The signal that is emitted when the show and hide animation that shows the inventory has finished. Inventory.gd emitts this signal in its _show_and_hide() method.

  • item_added( PopochiuInventoryItem item, bool animate ). Emitted by this class in the add_item method to notify the Graphic Interface that an item was added to the inventory. This is what makes the item to appear in the inventory (Inventory.tscn).

  • item_add_done( PopochiuInventoryItem item ). You can connect to this signal to know when a PopochiuInventoryItem was successfully added to the inventory. This signal is emitted by Inventory.gd.

  • item_removed( PopochiuInventoryItem item ). Emitted by this class in the remove_item method to notify the Graphic Interface that an item was removed from the inventory. This is what makes the item to disappear in the inventory (Inventory.tscn).

  • item_remove_done( PopochiuInventoryItem item ). You can connect to this signal to know when a PopochiuInventoryItem was successfully removed from the inventory. This signal is emitted by Inventory.gd.

Public

Private

Methods

  • add_item( String item_name = '' , bool is_in_queue = true, bool animate = true ) void

    Adds the PopochiuInventoryItem with script_name equals to item_name to the inventory. If you want to use it outside a run, send is_in_queue as false. Pass animate as false if you do not want the inventory to animate when the item is added. If success, it will return the PopochiuInventoryItem of the item added, otherwise it will return Null (might be that the item was not found or that the inventory is already full). Can be yield.

var ii: PopochiuInventoryItem = yield(I.add_item('Key', false, false), 'completed')
if ii:
  prints(ii.in_inventory) # Prints true
else:
  prints('Something went wrong')
  • add_item_as_active( String item_name = '' , bool is_in_queue = true, bool animate = true ) void

    Adds the PopochiuInventoryItem with script_name equals to item_name to the inventory and makes it the current selected item (the cursor will look like the item's texture). If you want to use it outside a run, send is_in_queue as false. Pass animate as false if you do not want the inventory to animate when the item is added. If success, it will return the PopochiuInventoryItem of the item added, otherwise it will return Null (might be that the item was not found or that the inventory is already full). Can be yield.

func on_interact() -> void:
  # The Inventory will animate because the 3rd parameter is true by default
  var ii: PopochiuInventoryItem = yield(I.add_item_as_active('Key', false), 'completed')

add_item_as_active

  • is_full() bool

    Returns true if the inventory is full. This depends of the property E.inventory_limit.

  • is_item_in_inventory( String item_name ) bool

    Returns true if the PopochiuInventoryItem with script_name equals to item_name is in the inventory.

  • remove_item( String item_name = '' , bool is_in_queue = true, bool animate = true ) void

    Removes the PopochiuInventoryItem with script_name equals to item_name from the inventory (its instance will be kept in the _item_instances array). Pass animate as false if you do not want the inventory to animate when the item is added. If you want to use it outside a run, send is_in_queue as false. Can be yield.

  • set_active_item( PopochiuInventoryItem item = null ) void

    Makes the cursor use the texture of item. Call this method without parameters to make the cursor takes its default appeareance.

  • show_inventory( float time = 1.0, bool is_in_queue: = true ) void

    Makes the inventory to show for time seconds and then hide. If you want to use it outside a E.run(), send is_in_queue as false. Can be yield.

    Useful to show where the inventory is during a tutorial.

func on_interact() -> void:
  # Make the inventory to show for 3 seconds
  I.show_inventory(3.0, false)

I show_inventory

Clone this wiki locally