Cleanest Way to Immediately Destroy Objects

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • If I understand correctly issuing an order to destroy a unit only happens at 'garbage collection' when CF2.5 reaches the bottom of your lines of code and wraps around.

    This was creating problems for my code, as it is able to finish an entire 'turn' that includes "player moves and kills an enemy unit" and "check for what Enemy units still exist, in order to decide rules for Enemy unit spawning for this turn" in one go-through. Since the destroyed enemy is only removed at the end, the code falsely insists the destroyed unit is still present when doing the latter check.

    I was able to identify several means to bypass this, but which they have issues I don't like:

    A: Having "every fraction of a second" built in to require the code to progress the timeliness of action to action, which creates a 'delay' long enough to shuffle past the end and force garbage collection. This doesn't work for my needs because "every fraction of a second" doesn't play well with fast loops.

    B: Have destroyed units be made 'legally dead' by making the condition that destroys them also set their Alterable Variable K=1, then make their K=1 a condition for things like "check what Enemy units still exist". This works, but necessarily requires tacking on K=1 condition to every possible event a 'live' unit might interact with, and requiring every Per Enemy Fast Loop still have to waste energy looking at dead enemies.

    I can use method B if I have to, but if there is a clean way to make Destroy=Instant Death I'd prefer to use such instead. The fewer conditions and complexities in the code, the better.

  • I think your B approach is the best one, at least if I understand you correctly. That's the one I always use, although I use a flag instead. Is_Destroyed = Off: object is still alive. You can use it in combination with ForEach loops, and have the condition in the event that start the loop, that way it will only start a loop with the objects that are not yet destroyed.

  • Checking flags is very cheap, performance-wise, so while you might not like the inconvenience, you at least don't need to worry about the performance cost. Checking altVals is cheap too, but flags are even cheaper.

    You might also want to move enemies to some other 'garbage' layer when you destroy them. That would make them automatically immune from any subsequent is overlapping checks, without any extra conditions required.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

    Edited 2 times, last by Volnaiskra (May 22, 2023 at 2:31 AM).

  • I think your B approach is the best one, at least if I understand you correctly. That's the one I always use, although I use a flag instead. Is_Destroyed = Off: object is still alive. You can use it in combination with ForEach loops, and have the condition in the event that start the loop, that way it will only start a loop with the objects that are not yet destroyed.

    Checking flags is very cheap, performance-wise, so while you might not like the inconvenience, you at least don't need to worry about the performance cost. Checking altVals is cheap too, but flags are even cheaper.

    You might also want to move enemies to some other 'garbage' layer when you destroy them. That would make them automatically immune from any subsequent is overlapping checks, without any extra conditions required.


    Thanks for the suggestion to use flags, keeps it more performance efficient at least.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!