cant get this to work

This forum is currently in read-only mode.
From the Asset Store
High quality sound effect pack, in the following categories: Garden work, tools
  • delete formation group:

    +for each formation

    +formation uid = ship('idformation')

    - set formation('ships') to ship.count

    it works so far, it counts 5 and when a ship is destroyed it counts down

    but it never reaching 0 , always stops at 1 ship even when all are destroyed

    i checked the id's and they all match, why doestn't it count to 0?

  • When there are no ships left, the formation uid = ship('idinformation') condition returns false, since there are no ships, so it doesn't set the count that time. You'll have to add another event to account for that case.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thanx mipey for pointing that out,

    i have fixed that by inverting the code, and it works now,

    but ran in another problem when creating more formations

    so this is what i got now

    ships = 0 destroy formation

    +for each formation sorted by formation UID

    + inverted | formation uid = ship('idformation')

    • set "ships" to countmatching(ships)

    so i thought countmatching would only count the ships for the current loop,

    but instead adds to the total number of ships, any idea why this happens?

  • Countmatching expression picks all selected instances. I don't think the ships were filtered at all, so it picked all. You can guess the outcome.

    Try this... create a (global) variable named 'allships', that tracks the total number of ships (though that may not be necessary, if you use Ships.Count, but I'm not sure if that is influenced by selection).


    +for each formation sorted by formation.UID

    +inverted | ship('idformation)=formation.UID //this should select all ships that are NOT in the current formation)

    -set "ships" to 'allships'-countmatching(ship) // all ships minus ships not in current formation = number of ships in the formation

    Empty formations should have 0. A bit roundabout, but this should work. Perhaps someone else has a more elegant solution. Also, try using Ship.Count instead of 'allships', if it is not influenced by selection.

  • nope, didnt work, all formations where constantly destroyed,

    i also gave the ships an formation group pv at creation , sorted by that, but then it crashed when the last ship destroyed, i guess its that damn bug again, when no objects exist and you loop trough it it crashes,

    how the hell do you check an object for to be zero when there has to be an object to count

    ill go back to my first implementation that has some error,most are destroyed, some are left behind dont even know why, but im loosing to much time on this one,

    anyway thanx for the help

  • Eh, Sprite.Count works for me, so I don't really know what is up... maybe someone else can look into this problem?

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