Create inventory HELP!

Get help using Construct 2

Post » Thu Apr 11, 2013 4:41 pm

Hi, im new to Construct 2 and i want make a game.
I created a tomato plant that drops 1 tomato when it's clicked and i created a tree where you can pick up some wood.
For three days i thought how i can make an inventory, but i don't know how use arrays for inventories.
I want create a simple inventory where i see the objects on a HUD and when i click the tomato the tomato is destroyed, and if i pick up the wood when the tomato is in inventory the wood go next the tomato, and if i click the tomato when the wood is in inventory, the tomato is destroyed and the wood take the first position on inventory and so on.
Can you post under this post some .capx project where i can learn your inventory system? Thanks very much!!
P.S
I saw all posts published on the creation of inventories but no one is right for me.
Bye
B
2
Posts: 3
Reputation: 260

Post » Thu Apr 11, 2013 6:27 pm

While there are undoubtedly ways to make inventories without Arrays, they're really the best option (at least in my opinion). Here's an example I made for someone else a while back. It should show you the basics:

Demo
Annotated Capx
B
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Thu Apr 11, 2013 7:03 pm

Thanks man, i have already downloaded your .capx in another post, my problem is that your .capx haven't a metode that when i click "cheese" (for exemple) cheese is destroyed and, if i pick up another "cheese" this return on inventory next to other objects and in another "slot".Another problem is that for exemple the tomato when clicked i can eat it and destroy the inventary item, but for the wood i don't want that when clicked it's destroyed, how can i do this in array? Can you modify your project for me? Thanks..really!
Sorry for my bad english.
B
2
Posts: 3
Reputation: 260

Post » Thu Apr 11, 2013 7:23 pm

Each X cell in the array represents an item. If you want to remove (destroy) one of the items in your inventory, Delete the cell with the item you want to destroy. In my example, each X cell contains an item name. If you want to destroy the item named "cheese" from the inventory, use the action:

Delete index (Inventory.IndexOf("Cheese")) from X Axis

This finds the X index of the cell containing "Cheese", and deletes it. Here's a modification of my previous example:
Demo
Capx

Learning how to manipulate arrays is an extremely useful skill that is definitely worth learning.

Edit: Fixed the Capx linkzatyka2013-04-11 19:59:10
B
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Thu Apr 11, 2013 7:38 pm

[QUOTE=zatyka] Each X cell in the array represents an item. If you want to remove (destroy) one of the items in your inventory, Delete the cell with the item you want to destroy. In my example, each X cell contains an item name. If you want to destroy the item named "cheese" from the inventory, use the action:

Delete index (Inventory.IndexOf("Cheese")) from X Axis

This finds the X index of the cell containing "Cheese", and deletes it. Here's a modification of my previous example:
https://dl.dropboxusercontent.com/u/4756521/Construct%20Demos/InventoryV2/index.html

Learning how to manipulate arrays is an extremely useful skill that is definitely worth learning.[/QUOTE]

Your .capx link is broken ;(
B
16
S
4
G
4
Posts: 56
Reputation: 2,942

Post » Thu Apr 11, 2013 7:58 pm

Thanks Zatyka with your exemple i start to learn, i have the last one question, how i can set the tomato,potato,carrot in the (edible /destructible) and wood, stone, grass in the (usable to craft/ undestructible) in the the same array with same properties except destructibility?
Make final exemple? Thanks
PS
The .capx download is broken.
B
2
Posts: 3
Reputation: 260

Post » Thu Apr 11, 2013 8:06 pm

Sorry about that. The link to the Capx is fixed.

@Ancor
Using the method in my example, you would create another instance variable in the gameitems sprite and name it something like "Destructability", and set it for each gameitem instance. Then, when picking up the item, add the "destructablility" instance variable to the Inventory array along with the the Item's other info (i.e. name and description). Now that the data is stored in the inventory array, you can do whatever you want with it.

Look at how I'm storing the description of each item... the same principles apply to any item data you want saved.zatyka2013-04-11 20:08:17
B
44
S
13
G
7
Posts: 338
Reputation: 10,379


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests