How do I have Drag and Drop Object Snap Back to Inventory Slot?

0 favourites
  • 4 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello,

    I am creating a survival game with an inventory system. The inventory system consists of three objects, the inventory slot, the resources, and an array to keep track of everything. The resources, a single frames with multiple frames that correspond with the Item ID, can be moved around through the drag and drop behavior when the Inventory is active. When the item is over a slot, it will snap to the spot so that you can organize your inventory how you like. This system is created by using instance variables. Each slot has its own slot number that makes it unique. The items have a the same instance variable that changes based on what slot it is in. When I drag one of the items away from the slots, it does not snap back to its original slot, the slot that shares the same slot number instance variable. Here is a screen shot of the code

    When the items (AlmightyStuff) is dropped, the game will check to see if it is overlapping any inventory Slots (InvSlot). If it is not, the game then compares the inventory Slots' instance variable Slot Number to that of the items's. If they are equal, then the items should set its position to that inventory slot.

    In theory, this should work, but it doesn't. Does anyone know how to fix this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • My first guess is that the engine does not know which InvSlot you are comparing because there was no overlap. You should use "for each -> InvSlot" and then have your check.

  • System condition you are using in the last subevent to compare SlotNumber doesn't pick InvSlot instances. You need to use "InvSlot Compare Instance Variable" condition for picking. You might also need to add "System Pick All" in front of it.

    Stuff on dropped
    Stuff is not overlapping InvSlot
    ... System Pick All InvSlot
    ... InvSlot Compare Instance Variable SlotNumber=Stuff.SlotNumber
    

    Edit: I did a quick test and "Pick all" is not required.

  • Okay, At first it didn't work but then I found the problem: When the Instances are first created at the start of the layout, they didn't set their slot numbers equal to that of the slot they were originally over meaning when I moved them away from the slots, they had no slot number imputed. Thanks again for the help!

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