Repeat....Having an issue

0 favourites
  • 5 posts
From the Asset Store
_____ Repeating Icing background game asset _____
  • OK, I have been using C2/C3 for over a decade and every once in a while I seem to run into this same issue and I just can't wrap my ahead around why it doesn't work. If someone can explain to me what I am not understanding about Repeat.

    On function GenerateBases (Param: NumberToGenerate)

    +Repeat NumberToGenerate times

    ++Pick a Random Spawner Instance

    Spawner: Spawn EnemyBase

    Spawner: Destroy

    I will still get EnemyBases being spawned on the same location. I know it's user error and I am not understanding Repeat. Help appreciated.

  • The problem is that objects are not destroyed instantly. So the loop can still pick the spawner instance which has been destroyed. A simple solution is to check another condition, say make destroyed spawners invisible and pick only among visible instances.

    +Repeat NumberToGenerate times
    ++Spawner Is Visible
    ++Pick a Random Spawner Instance
     Spawner: Spawn EnemyBase
     Spawner: Set invisible
     Spawner: Destroy 
    
  • I tried that, getting the same results. I did double check that spawners are in fact visible to start.

    The problem is that objects are not destroyed instantly. So the loop can still pick the spawner instance which has been destroyed. A simple solution is to check another condition, say make destroyed spawners invisible and pick only among visible instances.

    > +Repeat NumberToGenerate times
    ++Spawner Is Visible
    ++Pick a Random Spawner Instance
    Spawner: Spawn EnemyBase
    Spawner: Set invisible
    Spawner: Destroy 
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • "Is visible" condition should be above "Pick random". You want to first pick all visible instances, and then pick a random among them.

  • Bingo! Thank you.

    "Is visible" condition should be above "Pick random". You want to first pick all visible instances, and then pick a random among them.

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