Detect If All Enemies Defeated

Discussion in 'How Can I...?' started by onetap, Sep 6, 2020.

  1. onetap

    onetap Avid Boxer

    Joined:
    Oct 14, 2015
    Messages:
    122
    Likes Received:
    34
    Is there a way for Buildbox to detect if all enemies have been killed, then trigger level complete?
     
  2. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190
    A no code solution would be to assign each enemy a point or a coin then use the Event Observer and monitor the points/coins detected in the Session Total which would trigger level complete.
     
    onetap likes this.
  3. onetap

    onetap Avid Boxer

    Joined:
    Oct 14, 2015
    Messages:
    122
    Likes Received:
    34
    How would I achieve this if the number of enemies is randomly generated each level?
     
  4. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190
    If the number of enemies is created randomly then my no code solution won’t work. You would have to set the number to a specific value for the no code method to work.
    Your scenario would require some coding.
     
  5. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    605
    Likes Received:
    360
    Increment a global variable (or local) each time you spawn an enemies and decrease that value each time an enemies dies. When that value is 0 then the level is completed. Link the condition to a timer that has 9999 value or something that fit's your gameplay style and check if the value is 0 every 1 second or more depending on your game.
     
    Codifie likes this.
  6. Codifie

    Codifie Avid Boxer

    Joined:
    Apr 17, 2018
    Messages:
    364
    Likes Received:
    190
    This is a really good idea for a no code solution.
     
  7. agha

    agha Boxer

    Joined:
    Jan 21, 2020
    Messages:
    42
    Likes Received:
    57
    Here is an in depth tutorial explaining how object count could be done with any number of randomly spawned onjects,
    Hope this helps solve the problem. bbdoc also included in the video description.
     
    onetap likes this.
  8. Vlad-NY

    Vlad-NY Serious Boxer

    Joined:
    Jul 21, 2018
    Messages:
    605
    Likes Received:
    360
    Good tutorial, well done!
     
  9. onetap

    onetap Avid Boxer

    Joined:
    Oct 14, 2015
    Messages:
    122
    Likes Received:
    34
    Worked a charm, thanks a lot!
     
    agha likes this.

Share This Page