Replies: 3 comments 1 reply
-
I assume you're talking about the .json resource that holds the item prototypes. Those aren't really meant to define the contents of individual inventories, they are just "templates" for items that you want to use in your project. The general workflow I imagined is something like this:
|
Beta Was this translation helpful? Give feedback.
-
|
I got another question when I was finishing this reply. Every single InventoryItem that is created in the grid is unique ? Its this way how it works or am I complicating too much things? |
Beta Was this translation helpful? Give feedback.
-
|
Ah, now I think I understand. You can set the default stack size and max. stack size in the item prototype, so that whenever you create an item with that prototype it will have that stack size. This section of the README.md gives a good example: {
// The default stack size and the default maximum stack size is 1:
"watch": {},
// A full deck of 52 cards:
"deck_of_cards": {
"stack_size": 52,
"max_stack_size": 52
},
// Half a magazine of bullets:
"pistol_bullets": {
"stack_size": 12,
"max_stack_size": 24
}
}With these prototypes the default stack size for a "deck_of_cards" will be 52 and can be modified using var new_item = inventory.create_and_add_item("deck_of_cards")
print(new_item.get_stack_size()) # Should print 52
new_item.set_stack_size(50)
print(new_item.get_stack_size()) # Should print 50
new_item.set_stack_size(100)
print(new_item.get_stack_size()) # Still 50, can't go above max_stack_sizeAs for your second question: yes, items are unique as long as they belong to separate stacks. Items in the same stack share all properties. E.g.: var new_item_stack = inventory.create_and_add_item("deck_of_cards")
# This sets the ID for all 52 cards. There is no way to set a property for only the 1st card in the stack.
new_item_stack.set_property("unique_id", "deck:1")
# But we can set the ID of a different stack
var another_item_stack = inventory.create_and_add_item("deck_of_cards")
another_item_stack.set_property("unique_id", "deck:2")
print(new_item_stack.get_property("unique_id")) # Should print "deck:1"
print(another_item_stack.get_property("unique_id")) # Should print "deck:2"I hope this answers your questions. Let me know if I still missed something. |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys, Im new to this addon, so i'm still struggling with this.
Going straight forward:
I found this addon quite unique and very powerful for what it proposes.
As the title says, what is the best approach for this?
To use the addon only with the .json, to serialize the items, can someone give some hints?
For example, the function: create_and_add_item() it only creates an "inventory_item" and adds it to the node inventory, and how to create in one pass all the .json i have in my project to become an "inventory_item" and avoid having headaches?
in case someone cares, here is my discord for faster comunication:
f0xer99
Thank you for this addon @peter-kish, wish you all the best.
Beta Was this translation helpful? Give feedback.
All reactions