Limit number of objects

Get help using Construct 2

Post » Thu Sep 06, 2012 6:16 pm

Hello everyone,

I'm new to Construct2, and I'm trying to create the following behavior:
- Create a new object each 0.5 seconds
- If I've reached 10 objects on screen, remove the first one.

what I have:
- System.Every 0.5:               Create object Obj
      System.Obj.Count >= 10
      System.Pick-nth-instance Obj(0)     Obj.Destroy


I hope I wrote it in an understandable way.
What I'm trying to do is get the first Obj instance and simply destroy it.


Thanks!
B
3
Posts: 9
Reputation: 293

Post » Thu Sep 06, 2012 6:39 pm

I don't get it, is it not working?
[quote]C2 increments the UID every time an instance of any object is spawned. C2 increments IID every time an instance of a specific object is spawned.[/quote]
Pick the object with the lowest IID and destroy it?
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Thu Sep 06, 2012 7:22 pm

Lowest IID is always 0.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Thu Sep 06, 2012 7:30 pm

[QUOTE=evyatron] Hello everyone,

I'm new to Construct2, and I'm trying to create the following behavior:
- Create a new object each 0.5 seconds
- If I've reached 10 objects on screen, remove the first one.

what I have:
- System.Every 0.5:               Create object Obj
      System.Obj.Count >= 10
      System.Pick-nth-instance Obj(0)     Obj.Destroy


I hope I wrote it in an understandable way.
What I'm trying to do is get the first Obj instance and simply destroy it.


Thanks![/QUOTE]

Also, it may help you: http://www.scirra.com/tutorials/361/understanding-uid-iid-health-of-enemies-and-rocket-smoke-trail
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,192
Reputation: 18,276

Post » Thu Sep 06, 2012 8:51 pm

Thanks guys!

What I ended up doing is:
Event: Obj.Count >= 10
-Sub Event: Pick All Obj
--Sub Event: Pick nth 0

Because this is done in the same timing event used to create the objects, if I did the "pick nth(0)" directly it returned the Object I just created. Does that make sense?

Is what I did OK, or did I over complicate it?
B
3
Posts: 9
Reputation: 293

Post » Thu Sep 06, 2012 9:05 pm

Could some one tell me what nth stands for?
B
40
S
11
G
4
Posts: 665
Reputation: 8,403

Post » Thu Sep 06, 2012 9:11 pm

http://www.thefreedictionary.com/nth

[quote]nth [?n?]
adj
1. (Mathematics) Maths of or representing an unspecified ordinal number, usually the greatest in a series of values the nth power
2. Informal being the last, most recent, or most extreme of a long series for the nth time, eat your lunch!
to the nth degree Informal to the utmost extreme; as much as possible[/quote]

I mean it's like to say, the last "number", the higher, the most recent.TELLES08082012-09-06 21:13:12
ImageImageImageImageImageImage
B
92
S
19
G
12
Posts: 1,192
Reputation: 18,276

Post » Thu Sep 06, 2012 9:15 pm

the "N" in "nth" is a number variable.
to say "nth element" is to say "any element that's in the index N".

N also means the number of items in a set. So if I have 10 instances of Object, N=10.
like TELLES0808 reply, it could mean the last item (since N literally is the number of items), but it could also mean "any number between 0 and N" (like in our case).
B
3
Posts: 9
Reputation: 293


Return to How do I....?

Who is online

Users browsing this forum: Evanetot and 17 guests