playMaker

Author Topic: Right approach for an Inventory?  (Read 2595 times)

Mayhem

  • Full Member
  • ***
  • Posts: 171
Right approach for an Inventory?
« on: March 11, 2013, 05:42:58 PM »
Hello there!

The last days i fooled around with PlayMaker, looked up the Actions, this Forum and now i'm feeling (in some degree) confident; at least i can handle the most "problems" by myself by now.

Now, i don't have really a problem, but would like to hear from you, if this is a good approach for an Inventory-System, so here is the setup:

- My Inventory is based on nGUI
- This Inventory contains three Sprite-Objects (only SpriteObjects, no Buttons, nothing):
  • - a 2x2 Grid- Spriteobject
  • - a Note-Spriteobject
  • - a Sticker-Spriteobject which hold the Note to the Grid

So. Within this Grid:



I have placed four empty GameObjects (Slot 1 - 4), one in each of the Gridfields center. So, if the Player walks around and picks up an item, it will be a child of one these Slots. At the moment, i am doing this:

- if the Player picks an Item up, a Prefab-Version (as a Button) of that item will be created at a certain Slot and this Slot will be made it's parent

But, first of all i have to check if one the Slots is available. I am checking this by
the "GameObject Has Children"-Action:



Then i make a "Bool Test" of the Stored Variable. If it is true, i am sending a certain Event to the InventoryMenu. If it is false, it goes to the next "Slottester" and so on.

In the InventoryMenu i run again a BoolTest (for certain reasons) and then the Item-Prefab is created:



It's working, really good. Worked it today and and tested it. But i am looking in further development and started thinking. Is this the best approach? You see, if i keep doing it this way, i have to make for every single item the Player may pick up this State-Cycle; i.e.

- every Item sends a unique Event to the Inventory Menu, which will make my InventoryMenu-FSM a biiiig FSM :D
- every Item has this certain Statepattern (which is not confusing at all)

Now i don't know if this is a good or bad approach and would like to hear some opinions.

In fact I started to think using ArrayMaker, but i don't have a clue where to begin with this "System" with Arrays.

Mayhem

  • Full Member
  • ***
  • Posts: 171
Re: Right approach for an Inventory?
« Reply #1 on: March 12, 2013, 12:44:15 PM »
No opinions on that?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Right approach for an Inventory?
« Reply #2 on: March 12, 2013, 01:09:06 PM »
I don't like the size of it, all that branching is not good.

I've been wanting to dig into an inventory system but I am currently trying to get some working Pathfinding, Inventory is next on my list.

I do have some sort of similar work with a build menu I'm trying to simplify tonight. Basically I'm finding more and more that I am making generic FSM's and just delivering different information to them. The build buttons just store that information, send it to the strand, it fills the variables and executes everything without much branching, especially not one branch for each different object type. I think the same principle would help with inventories, using Get Property, storing objects in variables and generalizing everything as much as possible.

ArrayMaker is also something I plan on getting into after Pathfinding alongside with the Inventory stuff because I keep hearing about how much it will help the process by using Arrays and storing data there.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

blackant

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
Re: Right approach for an Inventory?
« Reply #3 on: March 12, 2013, 01:28:16 PM »
arraymaker as a sample that you can follow to make your own inventory.