Random instances and Arrays!

Get help using Construct 2

Post » Sun Nov 25, 2012 3:19 am

I'm trying to get my program to efficiently pick random instances of an object. Everytime it picks a random instance, I want that instance to be removed from the next round of picking.

I thought I could do this by destroying the instance after it has been picked. To my surprise, destroyed instances are still being selected when I use the "Pick a random (object) instance".

I have a simplified .capx to illustrate my problem. My goal for this little example is to have 10 of the red squares destroyed and only a single "X" appended to that square's text box.

https://www.dropbox.com/s/63uuhoca3dqn03j/testing.capx

Is there another way to do this? Perhaps use an array and remove items from that array and have the array automatically shrink so that I know whenever I randomly pick a point in the array, I'm guarenteed to pick an item and not an empty space? Kinda like an ArrayList in Java. Thanks
B
10
S
3
Posts: 102
Reputation: 1,888

Post » Sun Nov 25, 2012 4:52 am

@farmerdwight

Interesting find. I think the object might be flagged for destroy, but not actually destroyed when the "Destroy" event is called.

Here's a solution using a Boolean variable:
http://dl.dropbox.com/u/33370253/SkipDestroying.capxaruche2012-11-25 04:53:36
B
157
S
114
G
8193
Posts: 42
Reputation: 4,105,239

Post » Sun Nov 25, 2012 5:30 am

Thanks, that's an easy fix!
B
10
S
3
Posts: 102
Reputation: 1,888


Return to How do I....?

Who is online

Users browsing this forum: Timedoor Indones and 29 guests

cron