Adventure Game Inventory array...

0 favourites
  • 10 posts
From the Asset Store
Inventory Aid
$4.90 USD
Create grid-based game inventories and items easily.
  • I'm following this idea:

    Hey Joel, here are some of the key things that helped me build an efficient inventory with an array.

    Create only one sprite for the inventory items, this sprite should have a different animation for every item in the inventory with an appropriate name. Let's say that you have 8 visible slots in your inventory. At the start of each scene create 8 instances of the inventory item, even if you're inventory is bigger than 8 slots, it's only about the visible slots. Position each of these items in the appropriate place, I create an image point in the inventory bar animation and set each sprite to that position e.g: create object 'invitem' on layer GUI at 'InventoryBar.ImagePointX"item1" etc. etc. Then run a function that fills the items to correspond with the array. Here's mine:

    So this first sets a variable stored in my inventory array to 0, then for each instance of my inventory item sprite it sets the animation to whatever is in the array at the value of this variable. For example if the value saved into my array's X at 0 is "Hat" it will set the animation to "Hat". Just make sure you've create an animation called "Hat" and it will work. Then it adds 1 to the variable, so the second time it runs this loop it will set the animation to whatever is in the array's X at 1. If the value is 0 this means the slot is empty and it sets the animation to default, i.e. an empty picture.

    Moving the inventory left and right isn't too difficult. You create a variable, lets call it invScroll, and you add 1 to this variable when the left key is pressed and subtract 1 when the right key is pressed. You also run a function after changing the value of invScroll, i.e. every time you press left or right. This function is almost identical to the one above for arranging the inventory, except instead of: set animation to Inventory.At(Inventory.item) it will be set animation to Inventory.At(Inventory.item+invScroll)

    Hopefully that makes sense and is enough to get you started!

    Now, this is okay, but this assumes you'll have every item appear in a fixed place *I THINK*. I'm not sure entirely, and I'm not sure if this is the best practice for building an array for an adventure game inventory system, but this example does work, I'm just not *QUITE* sure how to, say, push the array to the right to add the new item to the start, similarly, a cell would need to be removed if an object was used. Can anyone just clarify these couple of points and if this is the best way of building the inventory?

    EDIT: Yes, I've just made sure I INSERT the item in the array:

    Now, I'll need to figure out how to grab the correct cell for destroying it from the array when it's used/given awayetc.

  • Hmm, tried this:

    Doesn't work though?

  • try:

  • try:

    Hmm, afraid that doesn't work either, I'm re-running the loop afterwards, but the item is still present in the invetory after clicking.

  • I got it working, but seems to leave duplicates of other items in the array? Does delete remove the entire cell, and not just the value?

  • if you want to delete all "Badge" cells from inventory use

    indexOf() delete only first "Badge" cell

    ..I assumed that there is only one "Badge" cell on unknown index

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • if you want to delete all "Badge" cells from inventory use

    indexOf() delete only first "Badge" cell

    ..I assumed that there is only one "Badge" cell on unknown index

    Yes, there should only be one of each, but I'll keep this in mind if there's duplicates, thank you!

  • Having a bit of trouble determining if I should have a second page with the scroll or not, not quite sure how to effectively test if theres more items than can fit on each page.

  • Use a system > 'for', .... from array.width - 1 .... to ...... 0.

    Now you walk trough the array from the end to the start.

    Sub event .... Compare 2 values ... Array.at(loopindex) ... = .... "badge"

    Action ... Array > delte ... x-axes ... index = loopindex

  • I've done it!

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