randomly delete a specific number of instances

Get help using Construct 2

Post » Sun Aug 30, 2015 10:14 pm

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?
B
7
S
1
Posts: 64
Reputation: 585

Post » Sun Aug 30, 2015 11:26 pm

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.
B
12
S
7
G
7
Posts: 450
Reputation: 4,276

Post » Mon Aug 31, 2015 8:13 am

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
B
10
S
2
G
1
Posts: 51
Reputation: 761

Post » Mon Aug 31, 2015 9:43 am

@Borgi

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

Coin-coin le Canapin wrote: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?
B
7
S
1
Posts: 64
Reputation: 585

Post » Mon Aug 31, 2015 10:29 am

add instance varible "Dead"(false)

Image
(0=false;1=true)
B
67
S
24
G
7
Posts: 1,518
Reputation: 11,072

Post » Mon Aug 31, 2015 12:00 pm

@korbaach

It works perfectly.

Thank you very much!
B
7
S
1
Posts: 64
Reputation: 585


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests