Skip to content

Commit 47654cf

Browse files
Add constraint docs
1 parent d18026e commit 47654cf

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

docs/source/manual/inventories/constraints.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,18 @@ Creating a custom constraint
3838

3939
Create a new script and add choose extend :ref:`class_inventoryconstraint` or :ref:`class_gridinventoryconstraint` case you want to use the grid inventory.
4040

41-
.. image:: ./images/custom_constraint.png
41+
.. image:: ./images/custom_constraint.png
42+
43+
44+
You have 4 functions to expand, let's demonstrate the use of :guilabel:`&_can_add_new_stack_on_inventory` by limiting the amount of stacks you can have in your inventory:
45+
46+
.. code-block:: gdscript
47+
48+
extends "res://addons/inventory/constraints/inventoryconstraint.gd"
49+
50+
# This is the function that will be called when the item is added to the inventory
51+
func _can_add_new_stack_on_inventory(inventory: Node, item_id: String, amount: int, properties: Dictionary) -> bool:
52+
return inventory.stacks.count <= 2
53+
54+
This code above limits your inventory to only having 2 stacks, that is, if these two stacks fill all other items that you call with the add or transfer function will not be made and will return the excess number of items that were not added.
55+
You can see more about them in the :ref:`class_inventoryconstraint` and :ref:`class_gridinventoryconstraint` API documentation.

0 commit comments

Comments
 (0)