Create inventory HELP!

0 favourites
  • 7 posts
From the Asset Store
Awardkit
$5 USD
Create custom awards and achievement or use the many templates and create your own.
  • 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

  • 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

  • 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.

  • 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 link

  • 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.

    Your .capx link is broken ;(

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)