How do I make an inventory where items don't stack?

0 favourites
  • 5 posts
From the Asset Store
Tap the ball, control it, avoid touching spikes and score higher!
  • I'm making a game where you own a shop and buy and sell items. I've found numerous tutorials on making inventories, but all of them have one problem: items can stack. I don't want items to stack. I want items to take up more cells if more of them are picked up. I've tried modifying some examples to fit my needs but I can't figure out how to remove the item stacking feature. Thanks!

  • There is usually more than one way to do anything in C2.

    The example you have could be done by variables or by an Array.

    While we would like to help we don't know the structure that you are using or have. We either need an explanation of how it is structured or we need a file.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've set up the basics using an n*1 array, with n being the number of inventory cell. I have another array with information about each id, such as descriptions and names. The problem is, I don't know how or how to go about the player picking up new items. The new items the player picks up should be added to the first available slot in the array. Thanks for the help!

  • Depending on how many inventory slots you have. The amount in the array should match.

    You should be equal to the amount of spaces in your inventory array.

    Then you should give every inventory slot an ID number starting with 0.

    Let's say your inventory is 5 spaces wide and 4 height.

    So with the Inventory ID it would look like his.

    00, 01, 02, 03, 04

    05, 06, 07, 08, 09

    10, 11, 12, 13, 14

    15, 16, 17, 18, 19

    If you have 20 inventory slots then the array should be:

    0, No Item

    1, No Item

    ...

    ...

    18, No Item

    19,No Item

    This is because 0 counts as 1.

    Using the info in the Array you can then make up the inventory.

    Make a variable that you can use to identify items.

    You can have Variable "Item"

    If the item the player picks up is a potion you can give the "Item" variable a value of "potion".

    After the value of variable "Item" is changed it should put it's value into the array.

    The array would be something like this.

    0, Potion

    1, Potion

    2, Stick

    3, Rock

    ...

    ...

    18, No Item

    19, Rock

    When the inventory array is changed you should update the inventory instantly.

    If the player uses the potion in Inventory ID 1 then you can grab that value and use it to change the value of that row in the Array.

    It was a "Potion" so now it should be changed to "No Item"

    You have to do this by comparing the used inventory ID to the Row of the Array.

    Inventory ID 1

    is the same as

    Row 1 in the Array

    0, Potion

    1, No Item

    2, Stick

    3, Rock

    ...

    ...

    18, No Item

    19, Rock

    If player picks up another Rock, check the Array for the first Row with the value of "No Item"

    Grab that Row number. That would be Row 1 again since the player used it the potion in Row 1.

    0, Potion

    1, Rock

    2, Stick

    3, Rock

    ...

    ...

    18, No Item

    19, Rock

    Every time you add a value into the the Inventory Array you should grab the Row ID it is being placed in.

    If the item is placed in the Array in Row 1.

    Then you should create the Rock Image in the X,Y location of the inventory ID of 1.

    When the Item needs to be used then you should delete that Image of that object and get the ID location of the Item and change the Array Value in that row to "No Item".

    If the player picks up an item you need to change the variable "Item" to what was picked up and then destroy that item. Insert it's value into the array. After it is put into the array using the "Item" Variable. Then you should use it's row to figure out where inventory ID it goes into in the inventory. Then you create the Rock image to the inventory ID spot.

  • Alright, will work on this. Thanks for the help!

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