0 Favourites

How do I have the game count active objects?

  • 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!

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Use one of the Pick events that take an expression to pick based on your instance variable. Then use 'PickedCount' to get the total.

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