Get same variables as destroyed object

0 favourites
  • 8 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi guys, I would like to know how I can get the same variables from an object that was destroyed and created another one in real time.

    it works like this I have several objects on the screen with different variables from each other and when the object is destroyed another one equal is created in place and it is necessary for it to be created in place so that it gets the same variables of the destroyed object in real time, the part to create the same object I already learned with a string variable and in it I put the name of the object that will be created in its place as soon as the object is destroyed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Do you need to destroy it? How does the game work? You may be able to hide it and make it appear again.

  • Do all the create object mechanics before you destroy the old one.

    They are essentially instant so it will create and destroy at the same time to the users eye.

    If it needs to look destroyed first, create the new one as initially invisible and set it visible when ready.

    Or what lionz suggested if that is a possibility - sounds like it would save work.

  • Do you need to destroy it? How does the game work? You may be able to hide it and make it appear again.

    I put an option to drop items on enemies and also to create other enemies in place as soon as the previous one dies, so I need the new enemy that will be created in the same place as the other to copy the same variables of the previous enemy in real time, because enemies of the same type can have different variables and I want the new one that will be created in the same place to copy only the variables of the other enemy that was destroyed

  • Ya call of that info before you destroy the other object.

    Or call a function and send in all the details you need as parameters before you kill the object. Every time I do this it just ends up being messy though.

  • Ya call of that info before you destroy the other object.

    Or call a function and send in all the details you need as parameters before you kill the object. Every time I do this it just ends up being messy though.

    I created local variables to receive the variables of the enemies that were destroyed so that when using "OnCreate" nothing seems to work

  • Local variables are reset each loop, so once you are done with your event that data is lost.

    The object has instance variables, these will be wiped as soon as the object is destroyed.

    Global variables can withstand this - but they are not designed to hold an objects stats since you can have many objects all looking for different values at the same time.

    Here is how I worked with destroying enemies in my last project.

    Enemies have a variable Boolean I set when they are killed and then I destroy them.

    In a new condition if an enemy is destroyed and also has killed true (This eliminates 2 swords killing the same enemy during the same tick) I can call my loot function while still having that enemies position and name stored. I then pass these into a function so I can use them after my enemy loses that information lose the information.

    (Mine is done with Families - but it should hold true with multiple of a single enemy as well)

  • Local variables are reset each loop, so once you are done with your event that data is lost.

    The object has instance variables, these will be wiped as soon as the object is destroyed.

    Global variables can withstand this - but they are not designed to hold an objects stats since you can have many objects all looking for different values at the same time.

    Here is how I worked with destroying enemies in my last project.

    Enemies have a variable Boolean I set when they are killed and then I destroy them.

    In a new condition if an enemy is destroyed and also has killed true (This eliminates 2 swords killing the same enemy during the same tick) I can call my loot function while still having that enemies position and name stored. I then pass these into a function so I can use them after my enemy loses that information lose the information.

    (Mine is done with Families - but it should hold true with multiple of a single enemy as well)

    Thanks for your support and patience ^_^

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