randomly delete a specific number of instances

  • Hey!

    Here is my problem :

    I have got 10 instances of a sprite on my layout and I want that 5 of them would be deleted randomly at the start of the layout.

    In the example below, I use "repeat" and "pick a random" events.

    Surprisely, each time the layout restart, the number of removed sprite is different.

    example

    What am I doing wrong?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It doesn't update the instance list each time you remove one during the same event, so it sometimes targets instances that were already deleted.

  • A possible solution:

    create an instance variable for the obect, for example -> DeleteOrder

    On start of layout, set all of the instance of these object DeleteOrder to floor(random(Object.Count))

    Create a local variable, for example, NumberToDelete = 5

    Now use an ordered foreach based on DeleteOrder on the object you want to delete and add an other condition here, where NumberToDelete > 0

    action: delete Object, Subtract 1 from NumberToDelete

  • Borgi

    It doesn't works... Or I doing it in a wrong way and that means I dont understand your solution

    It doesn't update the instance list each time you remove one during the same event, so it sometimes targets instances that were already deleted.

    So... there is no way to randomly delete a specific number of instances at start of layout?

  • add instance varible "Dead"(false)

    (0=false;1=true)

  • korbaach

    It works perfectly.

    Thank you very much!

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