Help with this inventory code

0 favourites
From the Asset Store
Inventory Aid
$4.90 USD
Create grid-based game inventories and items easily.
  • Here on this image i'm trying to make when the player colides with an item, the item name and amount goes to the ItemPosition, but when I try testing this, nothing happens. I even checked on debug mode if something happened to the array, but the array was intact. Can someone help me?

  • Loopindex expression only works with System loops. When using Array For Each Element loop, you need Array.CurValue, Array.CurX and Array.CurY expressions.

    Also, if your array is 2D, then you probably need to store item name and item quantity in separate cells. Your current code tries to write them into one cell as a string:

    "Axe,2"

    Stop Loop action also won't work with this loop. You will need another way to stop it, for example reset the item quantity.

    So the correct code should look like this:

    For Each X element
    Array.CurValue="Nothing"
    Item.quantity>0
     : Array set at (Self.CurX, 0) to Item.name
     : Array set at (Self.CurX, 1) to Item.quantity
     : Item set quantity to 0
     : Item destroy
  • It's working fine, but the game doesn't change the item icon animation by Items.Name

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It must be a different issue. You need to share a new screenshot or your project file.

  • This is where the game creates the inventory layer

  • And I use this array file called ItemPosition to determine the position of each item when the layout starts

  • So you are storing "name,quantity" strings! Then ignore what I said about writing them to different cells.

    I don't see anything wrong on your screenshots.

    What is the problem again? The icon is not updated when you add an item to the inventory?

  • Yes, when I collide to the item, it doesn't appears. The inventory looks intact, but on the itemPosition array it looks changed

  • Then you need to show the code where the inventory screen is updated after picking up an item.

  • The problem is that I tried using ItemIcon: Set animation to: tokenat(ItemPosition.CurValue,0,",") when the item was added to the array. But, the inventory displays the item I got in all slots

  • You need to show the code, the entire event.

  • You need to pick the correct ItemIcon instance, corresponding to the array element. Without picking, the animation will change for all ItemIcon instances.

    When ItemIcon sprites are created, give them two instance variables - invX and invY.

    Set invX to ItemPosition.CurX
    Set invY to ItemPosition.CurY
    

    Then, when an item is picked up and you found an empty slot, you can pick ItemIcon instance by invX and invY.

    Also, if I undertand correctly, your inventory array has 4 rows and 8 columns. So you need to use "For each XY element" loop. (not "For each X")

  • I changed the code to this, but now all slots look empty. Also, the first item, the Steel Sword, 1, was changed as well on both the array and the inventory slot

  • Why do you pick by lowest value?? Use "ItemIcon compare variable" condition:

    ItemIcon compare variable InvX=ItemPosition.CurX
    ItemIcon compare variable InvY=ItemPosition.CurY
    

    And, as I mentioned earlier, when using "For each element" loop you need the way to stop it. Otherwise it will update all slots with "Nothing" value.

    It would've been a lot faster if you could just share your project file.

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