Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What would be the best method of making a "grid" inventory system?

Asked by 6 years ago

For a point of reference, a normal inventory system would have a dictionary/table with a list of items and a number or "code" for the item's and then when a player picks up an item It could go to a folder or another table to store what's in the back pack. However, what would the best way to do it via how many grids you have left, kind of like that game Tetris where you have to rotate the objects and organize it in a way that you can fit more?

-- For those who like to be rude and say this isn't a request site, this is Indeed a request site, for help, not for code. Did I ask for any script in my question? No, I did not. However feel free to leave a piece of a script to help EXPLAIN the best method of achieving this goal. --

2
People who state that a posted question is phrased as a request are not being "rude," they're simply asking the user to post a question that will help them learn more effectively. Just wanted to address that. ScriptGuider 5640 — 6y
0
I'm aware but if you read one of my last posts, probably a week ago, there was someone who commented it wasn't a request site, and one other person and I had to correct him. Stephenthefox 94 — 6y
0
some questions come off as "give me code thanks" and that's what they're referring to when they say it's not a request site User#22604 1 — 6y
0
I know exactly what they are referring too, which is exactly why I got upset. Could you tell me why you down voted the question? What exactly did I do wrong with the question? Stephenthefox 94 — 6y
View all comments (3 more)
0
It is not a request site for free code, yes. But this isn't exactly a request site for help either. Staff members nor the community are obliged to help. We all have lives outside of SH. And if they say your question was a request when the intent of the question was not to be, it is most likely because you worded it poorly. You should read the "concepts" section of this: https://scriptinghelpers.or User#19524 175 — 6y
0
Thank you for the tip, @incapaz. Stephenthefox 94 — 6y

1 answer

Log in to vote
1
Answered by
WoolHat 53
6 years ago

This is an interesting question.

I have never attempted a grid inventory system, however, I would approach it as such:

Have a two-dimensional inventory array. Each index would hold either nil, or a reference to an item (table with the item's properties, essentially) that that space occupies. One such property would be the FormFactor of the item. If you have an L-shaped (three vertical on the left, then one on the lower-right), it would be in a 2x3 array, represented in 1s and 0s:

1, 0
1, 0
1, 1

And on top of this, another property I would have is a top-left position. This would help with many methods you would need to manipulate this system.

You'd want to methods to:
-Determine if a cell is occupied -Place item reference into a single cell -Get inventory cell locations where an object would be located if top-left placed at location X. You can use this method to:
+Detect if an item can be placed in the inventory via boundaries
+Place item references into the necessary cells
+Clear an item's cells from the Inventory

And possibly more.

Ad

Answer this question