How Do I pick instances based on animation name?

0 favourites
  • 3 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • Hello, I am crhttps://www.construct.neteating an RPG and have finished creating a loot drop and inventory system that works. I am now working on making the items in my inventory actually usable. First, I'm working on potions.

    I have two objects to achieve this: Obj_item_potions_game and obj_item_potions_inventory. Once of these represents the dropped sprites in game, the other represents the smaller versions that appear in the inventory once they are picked up.

    Both objects have the same three animations: ID_ManaPotion, ID_FireBottle, and ID_HealthPotion. These animations represent the three types of potions.

    I have managed to allow the player to pick up and drop potions at will and have made it to where a middle mouse click on a health potion will heal the player by two which is what I want.

    My issue comes with adding more potions. I'm trying to make it to where the fire bottle potion gets placed in an active items slot when clicked while maintaining the quantity the player has.

    I've successfully made this happen, but it happens to all potion types. For example, I click on a fire bottle in the inventory, and it moves to the active slot, but ALSO heals the player, while when I click on a health potion it heals the player, but ALSO, moves a fire bottle into the active slot.

    Is there a better way for me to differentiate between my potions so I can make sure they are all doing their own respective things when my player tries to use them?

    (Also, I plan on figuring out how the fire bottle will actually be used once this problem is taken care of).

    Any help would be greatly appreciated!

    youtu.be/pZyvF4SmsHQ Video example of what is happening.

  • Is obj_item_potions_inventory a member of Inventory_Item family?

    You parent event (Mouse on clicked Inventory_Item) picks a family instance. But it doesn't pick obj_item_potions_inventory instance! Even if it's the same sprite, Construct treats them as different objects.

    So to fix this you need to pick obj_item_potions_inventory which was clicked. The easiest way to do this is to add this condition to sub-events (before comparing the animation name):

    obj_item_potions_inventory Pick by unique ID = Inventory_Item.UID
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That worked! Thank you so much. Yes obj_potions_inventory was a member of that family, I did not know construct treated those separately.

    Adding the code, you provided right before comparing animations did exactly what I needed. Thank you so much!

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