Trigger when objects with a certain value are all destroyed

0 favourites
  • 4 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hey everyone,

    I've been going mad trying to work this out. I've searched all over and cannot find the right way. Some instances come close but are still not fitting for what I want.

    In my game, fires can occur and they can spread to other objects. When a fire is created it is assigned a special ID in the form of an instant variable to identify that exact fire, when it spreads to other objects those fires will also carry the same ID as the initially created one so the game knows that it is the same fire just spread to another object. So in my game it is possible to have two different fires with two different IDs so the game can differentiate two different scenarios.

    What I'm trying to do is when a fire burns out (gets destroyed) and there are no other fires of that ID instance variable anymore, the game will update the player with that information.

    I know I can do

    Event Condition:

    • On fire destroyed

    - HUD icon for fire is on screen.

    - Pick HUD icon by comparison (with the same ID instance variable associated with the fire)

    - HUD icon is HappeningNow (boolean)

    Action:

    - Change HappeningNow boolean to false (which initiates other actions that tell the player the fire is not happening anymore).

    This works for every fire of that same ID so even if one of the fires of the same ID gets destroyed, and other fires with the same ID are still present, it will update the HUD icon. I just need to see how I can tell construct 2 that if the last fire with that ID instance variable is destroyed to initiate the action instead. I can't seem to get it right.

    Help much appreciated, thanks all in advance!

  • You could just add to a counter when a fire is created and subtract from a counter when the fire is destroyed and when that counter hits 0 you set the boolean to false. You can use different global variables for different fires, so if fire type A occurs add 1 to firetypeA, fire type A destroyed subtract 1 from firetypeA and for fire type B add/subtract 1 to firetypeB etc. Because the variable starts at 0 you could set up a separate variable that triggers, fireStarted when the counter hits 1, so you know to check if a fire has stopped only when it has started, you can then toggle fireStarted off when counter hits 0. That's the way I would do it anyway rather than comparing to see if a particular icon is on screen, variables seem safer.

  • Pick all FireSprite

    FireSprite compare instance variable = fireID

    System compare FireSprite.pickedcount = 0

    Make sure this is a sub event of whatever destroys your fire in the first place. Otherwise, you may need to add a trigger once while true condition.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks guys for your help. Both of you assisted in prompting me to get the right idea in play for my game.

    Plinkie; I initially did try to do the fire count thing, but I was doing it on the burning objects and on the fire object instance variables, which was a reverse solution. I stopped it because it wasn't counting down properly. Unfortunately, I was not able to do it via global variables because of a couple of reasons; I did not want to limit the amount of possible fires in my game and I needed a solution for the way I had it currently. However, your advice of counting the amount of fires to set it to false when the counter hits 0 is the direction I went with, but I counted them on the HUDicon which is not subject to be destroyed automatically without the player closing it off, and it was the way to go.

    oosyrag; your idea sounded good, but I was not able to implement the pickedcount part due to the way my HUD icons were set up, so instead I tweaked it a bit and now it works fine.

    From the advice both of you gave, I was able to get it to work in my game. Thank you for your help!

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