A little help with an inventory system?

Fayabella

  • Posts: 191
Hi,

I'm now adding an inventory to my game.
I've downloaded Luyren's inventory behaviour, but I'm honestly not sure where to start. I understand what it does, but I think I might need a little point in the right direction.

Thanks!

Luyren

  • *
  • Posts: 1687
My behavior only handles the "behind the scenes" stuff. It has custom blocks to add/remove items and check for items, so you can use those to add items to the player's inventory (for an item pick up, for example). Actually displaying the inventory information on screen is up to you though. We'd need more information on what you want to achieve to help further.

As for tips using it:
1- If you open the behavior and go to the event with the custom block to add an item, you will see the format each item is stored in. I think it's "Item Name/Amount", but you'd have to check the version you have to make sure. There's a block under Text that reads "split [ ] with separator [ ]", and you'd use this block when retrieving items from the inventory list to separate the name of the item and the held amount.
2- The custom blocks can handle all inventory interactions outside of menus, so get familiar with those.
2- You have to get familiar with lists to expand on it, or creating your menu.
Working.

Fayabella

  • Posts: 191
Alright, I think I'm getting somewhere. Just a few problems (I've attached the image of my code):

It appears that returning the amount of [item] in a slot isn't working the way I think it should, so I'm doing something wrong here.

And, when something is added to the inventory, then all the other '[Empty]' texts just disappear, and won't be drawn anymore.

Is this the right way to be going about it or am I doing it super inefficiently?

Fayabella

  • Posts: 191
In this picture, I've collected a single apple yet 6 slots fill up. I must be misunderstanding how your behaviour handles items/slots?

Luyren

  • *
  • Posts: 1687
In this picture, I've collected a single apple yet 6 slots fill up. I must be misunderstanding how your behaviour handles items/slots?
It will be more helpful if you share how you are adding the items to the inventory, and how you are drawing them on screen.
Working.

Fayabella

  • Posts: 191
The first picture is my scene's 'When Drawing' code.
I'm adding items to the inventory when I touch the apple actor by using the [Add (1) (Apple) to the inventory of (Player)] block. When I chop a tree down i add random integer between 9-15.

Luyren

  • *
  • Posts: 1687
My bad, I missed your earlier posts.
1- If you print the "get amount of [item] in inventory" block with an item after you pick it up, what does it print? Also try printing the inventory by itself, see what it outputs.
2- Instead of typing "null", you should use the null block, under Flow > Advanced, see if that helps.

Also keep in mind that the version on Forge is quite old. Should be serviceable, but it's probably a bit different than the one I have, so we might have a few discrepancies.
Working.

Fayabella

  • Posts: 191
I used the Null block and it didn't do anything, that's why I typed it.

[Flash] scripts.SceneEvents_2#init(833): Apple/null,Apple/null,Apple/null,Apple/null,Apple/null,Apple/null,Apple/null,Apple/null
is what i get when i print the inventory, and I get NaN when I print the amount of it.

Luyren

  • *
  • Posts: 1687
Here is an updated version of the behavior. I also added a Drawing event showing a variation of your code that displays the inventory the way you tried. Short version is that the old version is broken, a mistake that I probably fixed on my end but didn't upload: the code for individual maximum values by item was affecting stuff that it shouldn't affect.
Working.

Fayabella

  • Posts: 191
That works much better! Now, though, when I collect over 99 wood, it appears that it won't put any more wood in another slot. Is this a limitation of the behaviour or is there something I must do for this to work?

Fayabella

  • Posts: 191
Also, how do I check if there is a certain item in an inventory / a certain amount of item?

Luyren

  • *
  • Posts: 1687
You can change the maximum amount in general or on a per item basis, but the behavior itself doesn't support multiple stacks. I'm working on it right now, and will post again if I get it done.
As for checking for an item, just use the get amount custom block. If the amount is 0, you don't have the item.
Working.

Luyren

  • *
  • Posts: 1687
Added support for multiple stacks of the same item. I reworked the custom block to get an item from the index. It now returns the whole entry (Name/Amount) and you have to separate them (example in the drawing event within the behavior itself). Re-read the description of the behavior and of each attribute to make sure you get everything right.

« Last Edit: February 11, 2019, 03:46:00 pm by Luyren »
Working.

Fayabella

  • Posts: 191
Is there a way to update the behaviour without having to manually replace all the blocks?

Luyren

  • *
  • Posts: 1687
As far as I know, there is no way to do that. The actual changes to the behavior are pretty substantial to just send images with the changes.
Working.