Deleting certain objects in sequential order

Hello, I want when a player activates a detonator, a certain amount of objects would get deleted in a sequential order, like let’s say it’s between 1 and 10, 1 gets deleted first, then 2, 3 etc until we get to 10, and I don’t want them to get deleted all at once, I want them to get deleted each 0.5 seconds, I tried doing this with instance IDs but I can’t think of any way that doesn’t require making a sub-event for each individual object and increasing the “wait X seconds” action by 0.5 each time, especially that what I’m planning to do will go way beyond 10 objects, so I was wondering if there’s a more straight forward way of doing this

If you have instance ids from 1 to 10, you could start a detonation timer and create an event with the condition “detonation_timer.value > object.id * 0.5” (pseudo code) and an action to delete the object.

I’m not sure I exactly understand this, could you give me an example of the event? Also I forgot to mention that there will be multiple detonator objects, 1 for objects 1-10, another for objects 11-20, etc

Something along the lines of:


You may have to add an extra object variable to the object that’s blowing up to link it to the detonation object

Oh I do have a variable for it, although a question, would “BlowUpGroup.Id” delete the objects in order of the instance ID? And how do I make it stop deleting when it reaches let’s say the 10th one

Sorry, I forgot to mention BlowUpGroup is an object group that has all the objects which are deleted in order of their Id. This allows for different objects to be deleted, but you can make it just the one object. It works the same either way.

There are mulitple ways to stop it after 10 objects have been deleted. One is to keep track of how many have been deleted with a Variable. This works well if the id values are greater than 10.

Another way it to check the value of the id before the object is deleted. If it’s value mod 10 is 0 (so “mod(BlowUpGroup.Id, 10) = 0”, then pause the timer. Remember to add a resume timer in the detonation event.

The second option sounds better, just to make sure, the event will be:
Condition: Variable value of BlowUpGroup = “mod(BlowUpGroup.Id, 10) = 0”
Action: Pause detonation event
Right?

Yes, but make that a subevent of the timer check event.

Alright, I’ll try this when I can and see how it goes

Hi, so I was able to try this with objects 1 to 5 and they still get deleted all at once, here are the events

Yeah, it’s to do with the way GDevelop selects objects. The way you did it doesn’t select the object. If you do something like this:

it will work.

I tried this and while it did work, it seems to start working when changing IDs (Like swapping 1 and 4) or randomly? I removed the objects, placed new ones, gave them IDs from 1 to 7, and they work at first but stop working for some reason and go back to normal?

Events

Get rid of that first “timer > id * 0.5” condition. It’ll cause problems.

Thanks, it works well, there’s one last thing, I tried to do the mod thing to stop/destroy the timer but I don’t quite understand, I would like an example event for it, right now I have one detonator object, I want it to destroy object IDs from 1 to 5, and stop at 6, so I can have another detonator that would delete 6 to 10

Like this:




and remember to delete the object after checking the mod value. Otherwise, you’ll be checking against a potentially non-existent object, which can lead to interesting results.

I tried this with 2 detonators, and it does work but the way it does work is the first detonator you pick would delete the first 5, and the second deletes the rest, I want to have it so a specific detonator deletes the first 1-5, and a second detonator deletes 6-10, third deletes 11-15, etc, so that if i have 2 detonators ready for example, if i pick the second one first it deletes 6-10 instead of 1-5, that is all that’s left really

Then I’d suggest you add an extra variable, say called “id” on the detonator and named “detonator_id” on the objects, and link the objects to the detonator with the new variables. You’ll also need named timers, one for each detonator.

Can I have an example event with 2 detonators? where Det 1 deletes 1 to 5, and Det 2 deletes 6 to 10, Sorry I just can’t really figure it out with text

Here’s a solution that will work for any number of detonators. Rather than have a different named scene timer for each detonator, the timer is added to each detonator and a flag set to show it’s active. My earlier suggestion would be cumbersome to maintain and is infexible. Try this instead:

1 Like

How are the BlowUpGroup objects linked to the detonator in this method? Just wondering how it works exactly