How do I destroy by name?

0 favourites
  • 3 posts
  • Hi all,

    Currently when the player picks up an object it creates the sprite inside their inventory. I need to create the sprite (and not use animation frames for the inventory) for several reasons. What this also means is that if the quantity of the object = 0 I need to be able to destroy it.

    Since I want to destroy any object that could be in the inventory slot I need to be able to destroy by name by passing its name into a function. Unfortunately this action doesn't exist in Construct 3.

    Does anyone know how I can destroy an object by its name?

    Tagged:

  • It sounds like you have multiple objects with variables so you should be able to destroy them when you need without using this method, especially because if you are going to be able to pass the name that means you should be able to destroy it anyway.

    Something like:

    If item1 var_amount = 0 destroy item 1

    If item2 var_amount = 0 destroy item 2

    Or if you are using paid version you can use a family and add all the inventory items:

    If family"items" var_amount = 0 destroy items

    However if you want to pass a string to a function, in the event that you call the function, before the function call action, store the name in a local/global variable, and then check that variable inside the function, and at the end of the function clear the variable.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Add all inventory items into a family. You can pass object name as a parameter into the function, and use "System Pick by Evaluate" condition inside the function to pick the right object.

    System Pick by Evaluate ItemsFamily where ItemsFamily.ObjectTypeName=name

    .

    Another option is to add an instance variable ItemType to the family. Set correct values in ItemType for all items - for example "sword", "potion" etc. Then you can pick objects by this instance variable.

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