How do I have the game count active objects?

Get help using Construct 2

Post » Tue Apr 22, 2014 7:51 am

Dear all,

The situation:

An x amount (lets say 10 for the example's sake) of chests_spawn points are dotted around the level. Each spawn point is randomly selected every x seconds and spawns a chest of some designation to be looted by the player, at which point the chest is destroyed, making the spawn point available to be randomly selected again.

The time in between spawning chests is regulated by subtracting dt from a Global variable "ChestSpawn_Time": which chooses a random Chest_Spawn instance on = 1, and then creates a new "Chest" on 0, after which the counter is reset.

As I said, spawn points that have an unopened chest on them (check overlap) will not be selected when "ChestSpawn_Time" reaches 1.

So far so good.

The Problem

When all 10 spawn points are overlapping with chests there is no Spawn point instance to be randomly selected anymore. Naturally, "ChestSpawn_Time" will keep decrementing by dt into the -.

So, I was wondering if it would be wise to have the game count the amount of ChestSpawns on start of layout, save the number to a GV, say "ActiveSpawn_points", subtract 1 after every spawn, and simply stop the subtraction of "ChestSpawn_Time" once "ActiveSpawn_Points" reaches 0, and resetting it when it reaches >0.

If so, what would be the best way to count object instances?

Thanks!
B
7
S
2
Posts: 51
Reputation: 627

Post » Tue Apr 22, 2014 1:38 pm

Use one of the Pick events that take an expression to pick based on your instance variable. Then use 'PickedCount' to get the total.
ImageImageImage
B
71
S
22
G
247
Posts: 3,753
Reputation: 137,552


Return to How do I....?

Who is online

Users browsing this forum: The Mnk and 7 guests