Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: Mayhem on March 11, 2013, 05:42:58 PM

Title: Right approach for an Inventory?
Post by: Mayhem 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):

So. Within this Grid:

(http://www.kingpic.net/uploads/bildschirmfoto_2013-03-11_um_22_23_42.png)

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:

(http://www.kingpic.net/uploads/bildschirmfoto_2013-03-11_um_22_30_39.png)

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:

(http://www.kingpic.net/uploads/bildschirmfoto_2013-03-11_um_22_34_45.png)

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.
Title: Re: Right approach for an Inventory?
Post by: Mayhem on March 12, 2013, 12:44:15 PM
No opinions on that?
Title: Re: Right approach for an Inventory?
Post by: Lane 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.
Title: Re: Right approach for an Inventory?
Post by: blackant on March 12, 2013, 01:28:16 PM
arraymaker as a sample that you can follow to make your own inventory.