Sites


Creating Point and Click Games with Escoria

Inventory

The inventory is the UI that shows your current inventory items, and allows you to use them. It is located in the scene file ui/inventory.scn. The inventory will show items from a scene that contains all the items in your game. Items can be shown in multiple pages.

Building an inventory

The requirements of the inventory scene are as follows:

  • A root node of type Control, with the script globals/inventory.gd attached to it
  • A Control node named slots, with one or more children of type Position2D. These positions are the places where items will be shown as they appear on the inventory.
  • Button nodes named arrow_prev and arrow_next. These are the buttons to go to the next page and previous page of items if multiple pages are necessary (if the number of items in the inventory is greater than the positions in the "slots" node). They can be hidden if not necessary.
  • An instance of your inventory items scene, named items. This scene contains all the items of your game.

Escoria provides a default inventory scene you can find in game/inventory_items.scn. This scene contains a basic item but needs to be customized to add all the items of your game as children of a root Node2D node. The items must be fully functional Items, configured with their properties, sprite, script file, etc. For this type of item, usually a TextureButton is used with the globals/item.gd script attached to it, although any other type of item can be used. You can read "The Items" Chapter for details.

The inventory scene is a child of hud.scn which is a chid of game.scn. So it should be made available automatically in your game once game.scn in imported to your main scene. Refer to our Create your scene chapter to see how to do it.

Using the inventory

Now that the inventory is ready as a UI element visible to the user, it will be necessary to define how to use it. This will be done with an esc script description. Generally, adding an element to the inventory will be made from a pick_up action. During this action we generally have to :

  • enable the corresponding inventory item
  • make the object invisible in the main scene
  • optionally, play a "pick up" animation in our main character, say a line of dialog, etc

In the script it could look like this example we use in our intro game.

:pick_up

> [!picked_item]
  set_global i/inv_good_bamboo true
set_active good_bamboo false

Note that, since we add items to the inventory, we can use the global flag corresponding to the item to check if the user has it

> [i/inv_good_bamboo]
    # user has the good bamboo

Usually, using an inventory item will be used on a :use action

:use inv_good_bamboo

and you will probably need to unset all the necessary globals, conversely to the pick up action

Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.

Vous devriez rafraîchir la page.