How do I sort my inventory?

0 favourites
  • 6 posts
From the Asset Store
A master sorting Puzzle fun and addictive puzzle game! A challenging yet relaxing game to exercise your brain!
  • Heyo!

    I've got this inventory bar at the bottom of the screen which houses all my pickups.

    It's working well but I can't figure out how to sort the pickups so there won't be an empty space when I use one of them.

    Any suggestions?

    I have all the pickups in a family and the inventory slots are instances of the same object going from left to right.

    I have a drag and drop behavior on the Pickup-family that is only active when the pickup is dragged from the inventory slots. I don't want the inventory to sort in the way described above when an item from the inventory slots is dragging, only when it is used (destroyed).

    Attached screenshot for clarity and another one showing my basic inventory set up.

    Thankful for any helpful tips or tricks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could start using some kind of slot ID type mechanic so you can pick out the slots easier. Then if they were numbered 0,1,2,3 for example, the pickup would also be assigned the same value on a family instance variable when you pick it up, for each slot and not full etc set position to slot and set pickup ID to slot.ID, so you would have a pickup with ID 2 overlapping as lot with ID 2 for example.

    Then when you use a pick up you have its value, so the one in the screenshot missing would be 2. On destroyed, you can say for each slot ordered by slotID, if slotID greater than 2, subtract 1 from the pickup.var. This moves them all to the left by 1.

  • Thanks for the reply!

    That sounds like it should work. One thing it might be missing is that whenever the pickup variable is changed (like on destroy in this case) the pickups affected should move to their new respective slot.

    In any case, I'm working on a solution like you suggested and I think I must be making some really basic mistake here because I can't for the life of me get the code to pick pickups with id's > the empty slot (SlotEmpty = the destroyed item in this case).

    Please laugh at me and tell me what I'm doing wrong! :)

  • In terms of movement you can do it a few ways. One is to say if pickup.ID = slot.ID then set pick up position to slot, that way when you subtract 1 they will automatically move down a slot i.e. pickup.id=4 will become 3 and set its position to slot.ID=3

    You don't need that event for slot number you should just set the variable in the editor view.

    For the other one its because when you do on destroyed it narrows picked instances to 1, you then cannot pick more unless you do a sub event 'system pick all pickup', this opens them all up to be picked again, and then you can do the other event after it.

    Looks like you are on your way, with some tweaks and edits you will get there eventually with this mechanic.

  • Awesome, thanks so much for the help!

    I've got everything to work the way I intended now, to much relief. :)

    I won't take up more of your time, but I was just wondering what you meant with: "You don't need that event for slot number you should just set the variable in the editor view."?

  • The add loopindex to slotnr is to set the number of the slot I assume ? you can just do this in the layout is what I mean since the inventory is already there you can assign the variable on the sprite in the editor before you run the game.

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