Families and family variables.

0 favourites
  • 3 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Having trouble getting my head around this one.

    I have a spaceship, with 4 shields, aft/bow/port/starboard. I've put all of these into a family, with a family variable of health.

    10 times per second, I want to check these shields, and if they're not at full strength, they recharge, if there's enough power to recharge them.

    So my condition has 'Every 0.1 seconds. Shields - Strength < 100. Power > 1'

    Then the action is to recharge each chosen shield and drain the power from the ship. It works in one respect - each shield does recharge. However, the power is only drained once, even if all 4 are recharging. What I assume it does is, if the conditions pass, it does the action once - so if 2 shields are recharging, it recharges each shield, but it still only does the power drain once because it's only one action.

    So how do I get it to drained once seperately for each shield? I'd like to do them one by one, so that if for example, there's enough power to charge 1 up, but 2 require recharging, one will recharge but the 2nd won't.

  • There are many different things you could do. The most simple of which would be to target the shields individually instead of grouping them together.

    Then you could have events for each shield.

    Every tick

    EnergyBank > 0

          Shield1Energy < (fullamount)    ->Subtract 1 from EnergyBank

                                          ->Add 1 to shield1Energy

          Shield2Energy < (fullamount)    ->Subtract 1 from EnergyBank

                                          ->Add 1 to shield2Energy

    If you wanted to reuse your 1 shield object then you just have to select the individual instances of these objects to check for instead of Shield1, ..2 etc.

    I hope that gives you some food for thought.

    Edit: if your not looking for the easiest solution and want the shortest way of coding it instead, then play around with adding 'For each object' system command to what you currently have.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, I couldn't really have individual events for each shield as it was more complex than just those calculations, so I needed to group them. After an evening of scratching my head, I finally worked it out. For anyone in the same position, the answer was indeed to use the 'For Each' command, although I had tried that earlier but couldn't work it out.

    My answer was...

    System : Every 0.1 seconds - No action

    Shields : Strength < 100

    (sub event)

    System : For each shields - No action

    (sub event)

    If enough energy, recharge the shields.

    The double sub-event solved it. Basically nothing happens until it gets through to the final event, and that event is specific to each individual shield, but now runs 4 times (or however shields need recharging) instead of just once, and recharging all shields in a single action.

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