How do I make an inventory without array

Get help using Construct 2

Post » Sun Mar 23, 2014 4:24 am

Anyone?
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Sun Mar 23, 2014 6:06 am

Here's a brief overview of how I handle inventory in Courier. I'll not be posting code snippets, but I think the description will help you.

First off, I use one big array for most of the data in my game--I use global variables for other stuff. In Courier, you have two types of items. I have 6 items that you can accumulate more of (potions, money, etc), so I just have 6 array slots with a count. Add one, subtract one. That one's pretty simple. I also have 4 slots that can take any one of a ton of essentially quest items. I have a single Quest sprite and all subsequent icons are saved as frames of that same sprite. I have a copy of that sprite with an instance variable sitting in each of the quest slots (be sure to have a blank frame for empty!) I have the 4 cellsin my array and, at the start of a quest, I set that cell to that quest's number. I have an external spreadsheet (ie, excel/google spreadsheet) to help me keep track of this stuff. I also have reminders for what coordinates go with what information. Once that quest is put in that cell, I update the corresponding icon to the frame that matches that quest item. I also have a 5th "holding" cell so I know what the user is deciding about (you can accept or deny taking on quests). Once the user selects where that quest item will go, I reset the holding cell to 0.

As a side note, I also use my array to keep track of the status of each quest/delivery. If the value is 0, it hasn't been attempted. If it is 1, it is currently in-progress, and if it is 2, it is completed. This helps with characters speaking in context and making game events happen when they should.

If you want a non-static list of these things, you could go through every slot (coordinate within a certain column, for example) and look for how many 4's you have and say you have 4 potions, etc. So you could take the general list in that column and make a visual display, but you could also loop through it and make a compressed list with quantities. Such is unnecessary for my game, but definitely a logical expansion of it.

So if you have just quantities of a certain number of items, just have a cell dedicated to each item and run with a total count in each cell. If you have multiple one-off things, I would think of having a certain number of dedicated cells (or dedicate an entire column and just add to the end--pay attention to the dimensions of your array so you don't run out of space) and set those cells to a number that means something to you. So assign each item a number (in your head, on paper, something) and assign cells to those numbers. You now have a list of the items the player is holding can you can make your visual display relative to that data. Just remember to think of arrays as spreadsheets and you'll be fine.
B
103
S
38
G
19
Posts: 962
Reputation: 17,996

Post » Sun Mar 23, 2014 6:37 am

@C-7

Thanks man.

My inventory is working partially because I didn't figure out how I can drop an item "visually". In other words, the picking and dropping is working on my array, but I need to drop right next to my character that item. And that's the problem because i'm using family. I'm trying to get the information on my array that identifies which item I had stored and relate to the object that I must spawn right next to him.

Image
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Sun Mar 23, 2014 7:57 pm

Anyone?
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Previous

Return to How do I....?

Who is online

Users browsing this forum: FacuLNF and 65 guests