Skip to content

PopochiuInventoryItem

Carenalga edited this page Feb 6, 2023 · 9 revisions

icon_inventory_item-x4

Description

Inherits TextureRect.

An object the player can grab and use in Props, Hotspots, characters and other inventory items. It is similar to PopochiuClickable but as a Control node.

Properties

Signals

  • description_toggled( String description ). Emitted to show or hide the object´s description when the cursor is over it or leaves it. The graphic interface connects to this signal in order to show or hide this text.
  • selected( PopochiuInventoryItem item ). Emitted when the object is clicked in the inventory. Inventory connects to this signal in order to change the pointer texture by the one of this object.

Export

  • cursor. Cursor. Default Cursor.NONE. The cursor to show when the pointer is over this object.
  • description String. Default ''. The text shown to players when the cursor hovers the object.
  • script_name String. Default ''. The identifier of the object used in scripts.
  • stack bool. Default false. Whether the object can be stacked. ⚠️ Not used yet by any script ⚠️.

Public

  • amount int. Default 1. The number of this objects. ⚠️ Not used yet by any script ⚠️.
  • in_inventory bool. Default false. Whether the object is inside the inventory.

Methods

Virtual

🍑 For a detailed and exemplified description of all the virtual methods of this class, go to the Your scripts > Inventory item page 🍑.

  • on_added_to_inventory() void

    Use it to define custom behaviors once the item enters the inventory.

  • on_discard() void

    Use it to define custom behaviors when the object is discarded from the inventory.

  • on_interact() void

    Use it to define custom behaviors when players INTERACT (click) with the object. ⚠️ By default this function emits the selected signal, so take this into account when adding your code.

  • on_item_used( PopochiuInventoryItem item ) void

    Use it to define custom behaviors when another item is used on this one. By default this function shows a game message ( G.display() ) warning the player that there is nothing defined for that action.

  • on_look() void

    Use it to define custom behaviors when players LOOK AT/EXAMINE (right click) the object. By default this function shows a game message ( G.display() ) warning the player that there is nothing defined for that action.

Public (since v1.9.0)

  • add( bool animate = true ) void

    🍑 Intended to be used inside an E.run() (a.k.a. queue of instructions) 🍑

    Adds this item to the inventory. Pass animate as false if you do not want the inventory to animate when the item is added.

    func on_interact() -> void:
      E.run([
        C.walk_to_clicked(),
        "Player: I'm gonna take this with me",
        I.Key.add()
      ])
  • add_now( bool animate = true ) void

    Adds this item to the inventory immediately. Pass animate as false if you do not want the inventory to animate when the item is added.

    func on_interact() -> void:
      I.ToyCay.add_now(false)
    
      E.run([
        "Narrator: Goddiu slipped the toy car into his pocket without anyone noticing",
      ])
  • add_as_active( bool animate = true ) void

    🍑 Intended to be used inside an E.run() (a.k.a. queue of instructions) 🍑

    Adds this item to the inventory and makes it the current selected item (the cursor will look like the item's texture). Pass animate as false if you do not want the inventory to animate when the item is added.

    func on_interact() -> void:
      E.run([
        C.walk_to_clicked(),
        I.Knife.add_as_active(),
        "Player: Let's cut that cake"
      ])
  • add_as_active_now( bool animate = true ) void

    Adds this item to the inventory immediately and makes it the current selected item (the cursor will look like the item's texture). Pass animate as false if you do not want the inventory to animate when the item is added.

    func grab_blue_vase() -> void:
      I.BlueVase.add_as_active_now(false) # Do not show the inventory
  • remove( bool animate = true ) void

    🍑 Intended to be used inside an E.run() (a.k.a. queue of instructions) 🍑

    Removes the item 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 removed.

    func on_interact() -> void:
      E.run([
        C.walk_to_clicked(),
        "Player: A cut here, a cut there",
        "Player: And I don't need these scissors anymore",
        I.Scissors.remove(false), # Do not show the inventory
      ])
  • remove_now( bool animate = true ) void

    Removes the item from the inventory immediately (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 removed.

    func on_room_exited() -> void:
      I.ToiletPaper.remove(false)
  • set_active( bool ignore_block = false ) void

    Makes the cursor use the texture of this item. If ignore_block is true the cursor will change even if the cursor is blocked.

    C.Guard.say('Give me your ID card')
    I.IDCard.set_active()

Set and get

  • set_in_inventory( bool value ) void

    Calls on_added_to_inventory() if the object is inside the inventory.

  • get_description() String

    Returns the description of the object passing it through E.get_text(), which can be used to show it in different languages when using localization.

Private

  • _toggle_description( bool display ) void

    Shows and hides (depending on the value of display) the description when the cursor hovers or leaves the object.

  • _on_action_pressed( InputEvent event ) void

    Determines the action made by the player when interacting with the object. If it was a click, then on_interact() is called, but if there is an active inventory item, then on_item_used() is called. If it was a right click, then on_look() is called.

Clone this wiki locally