Skip to content

InventoryItem

Carenalga edited this page May 17, 2022 · 6 revisions

icon_inventory_item-x4

Description

Each inventory item you create will have its own script file (based on InventoryItemTemplate.gd). This is created with the name you give the item in the Create inventory item popup prefixed by Inventory: E.g. InventoryMasterKey.gd, InventoryScythe.gd, InventoryCardDeck.gd.

Methods

  • on_interact() void

Called when "popochiu-interact" (set to Left Mouse Button in the project's Input Map) is used on the item. E.g. You can use it to make the item as the active item.

By default this calls to .on_interact(). In case you don't overwrite this, it will use the default PopochiuInventoryItem.gd on_interact() call, which shows a game message.

func on_interact() -> void:
  I.set_active_item(self) # Makes the cursor look like the item and be the PopochiuInventoryItem passed to on_item_used() methods
  • on_look() void

Called when "popochiu-look" (set to Right Mouse Button in the project's Input Map) is used on the item. E.g. You can use it to make the PC say something about the item.

By default this calls to .on_look(). In case you don't overwrite this, it will use the default PopochiuInventoryItem.gd on_look() call, which shows a game message.

func on_look() -> void:
  E.run([
    'Player: It is a master key.',
    'Player: I can go anywhere with this!'
  ])
  • on_item_used(item: PopochiuInventoryItem) void

Called when an inventory item is used on the item. Use the script_name property of item to see which was used.

By default this calls to .on_item_used(item). In case you don't overwrite this, it will use the default PopochiuInventoryItem.gd on_item_used(item: PopochiuInventoryItem) call, which shows a game message.

func on_item_used(item: PopochiuInventoryItem) -> void:
  if item.script_name == 'Bullet':
    yield(E.run([
      'Player: Great.',
      I.remove_item('Gun'),
      I.remove_item('Bullet'),
      I.add_item_as_active('LoadedGun'),
      'Player: Say hello to my little friend!'
    ]), 'completed')
  • added_to_inventory() void

Called after the item is added to the Inventory.

By default this calls to .added_to_inventory(). In case you don't overwrite this, it will use the default PopochiuInventoryItem.gd added_to_inventory() call, which does nothing 🤓 .

func added_to_inventory() -> void:
  if Globals.game_state.get(GameState.BATTERY_FULL):
    description = 'Battery charged'
  else:
    description = 'Battery empty'
Clone this wiki locally