Count objects returned by an event, cleaning up duplicates

0 favourites
  • 7 posts
From the Asset Store
Be quick and count the cards and choose the right number!
  • When you narrow down objects from an event like say

    x => x is overlapping y

    Is there an easy way to get the count of x that meets that criteria? I want to know HOW MANY Xs are overlapping Y.

    Also I have a level maker that stacks floor pieces on top of each other sometimes. This is a natural byproduct of the level generation. I'd like to be able to clean it up though.

    Something like

    for each floorsprite

    if floortsprite is overlapping another floorsprite (in floorsprite family), then destroy only the top floorsprite.

    This is kind of difficult, because there's no way of knowing during the same loop whether a thing has been destroyed or not. It ends up destroying BOTH floorsprites.

    Then, assuming I can only pick one how to get JUST the one on top?

  • For the first you can use x.pickedcount.

    For the second if it's tile based i'd use and 2d array for the grid and use a "for each sprite" to add each sprite to the array and if a spot is already occupied just delete the lower one.

    Or you could finagle picking to do it. A condition like "sprite is overlapping sprite" will pick all the sprites overlapping but that isn't what you want, and putting that after a "for each sprite" won't work cause then it would only check for collision with itself because only one instance would be picked.

    The simplest way would be to make two families of the same object types (or only one family if only one type is needed). Then do an event like this:

    for each family1

    family1 is overlapping family2

    pick top family2

    --- family1.zorder > family2.zorder

    ------ destroy familly1

    --- else

    ------ destroy family2

  • x.pickedcount! OMG. Thanks! I knew there was something like that but I couldn't seem to find it...

    I tried something like that with Object vs Family (of same object) and it still ended up destroying both but I haven't tried two families yet...

    Friggn pickedcount. #$%^ haha...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • OK Pick top does the trick! Man I've been wrestling with this for a while.

    The circles and squares are different frames of the same object.

    I made a grid of circles and sprinkled some frames on top of them...

    Left click anywhere to "clean up" the boxes from on top of the circles. It works without cleaning up the circles too.

  • OK this is a bit frustrating. There seems to be no reliable way to put a "wait" command in a loop and have it behave like a procedural language would behave.

    For example, in the above capx, what if instead of having it call the clean function when you click the mouse, you wanted it to call the clean function, wait 0.1, call it again, wait 0.1 again... say, 4 or 5 times?

    You can't go

    repeat 5 times

    call "clean"

    wait 0.1

    It only goes once.

  • Wait does not block. It puts any events underneath it to the side and runs them after the wait period. You could do:










    Or use a Timer with a counter.

  • That first method is what I end up using, it just seems unruly code wise. That's why I think we need a Sync command (or something) that just updates all the objects right then.

    Timer with a counter... that sounds interesting.

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