0 Favourites

Same pick operation an arbitrary number of times

This forum is currently in read-only mode.
  • I have a pick operation, if Sprite overlaps Sprite. I want to be able to repeat this an arbitrary number of times based on some variable, but I want each instance of the pick condition to remember the previously picked objects and run the condition with them. For example:

    If Sprite1 overlaps Sprite, Pick all those sprites

    If those picked sprites overlap other sprites, pick all those other sprites too

    and so on and so on

    I can do this a set number of times by making a chain of Sprite overlaps Sprite subevents, but looping doesn't seem to work since each Sprite overlaps Sprite is not done as a subevent to the previous ones, so it starts the picking process all over from scratch.

    Any ideas on how I can do this?

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Oh I also tried using recursion (e.g. have a function that calls itself some number of times) but Construct crashes when I try that =/

  • im not exactly sure what you're asking for, but using a combination of a loop and a PV to track which objects have been flagged as "picked" should work if i understand correctly.

    can you try clearing up your example, and use objects called "A" and "B", it's hard to understand which sprites you're referring to,

  • Yeap, using a PV will work. I'm just trying to avoid adding PVs if I can do it without it. I was hoping I could somehow recursively or otherwise apply the same 'Pick' filter to the picked objects list an arbitrary number of times. I'll use a PV to solve it if it's not possible otherwise though.



    Sprite overlaps sprite
    	[li]> Sprite overlaps sprite[/li]
    [/ul]     ->  Sprite overlaps sprite
                    -> Sprite overlaps sprite[/code:3fp1lo8e]
    So the result of doing that N times.  Notice that each is a subevent of the previous one, so it's operating on the items picked by the previous one, which is different from:
    Sprite overlaps sprite
    Sprite overlaps sprite
    Sprite overlaps sprite
  • So what your saying is once sprite overlaps sprite pick both sprite, and sprite, and add them to a list of sprites that will not be picked again unless they overlap a previously unpicked sprite.

    Yeah a pv wont handle recursion, so you need a list. Lucid's "S", Ars0nide's Datastructre plugs Deque, or even the List Box object will work. That with a pv, and a loop.


    Actually Uid rather than pv might be better here....

    Or multiple pv's

    Then you wouldn't need a separate object as each sprite could hold its index, as well as an "is selected" pv. But then you have to get tricky with picking and pv's to avoid adding previously selected sprites.

  • Hmm, why isn't this code doing it?

    Pick Sprite 1 -> Spite set IsPicked to 1
    For 1 to N
    ->Sprite: Pick by evaluate Sprite.Value('IsPicked')=1
        -> Sprite overlaps sprite  --> Sprite set IsPicked to 1[/code:g76ca2gi]
    Shouldn't each loop iteration pick all the sprites returned by Sprite overlaps Sprite, thereby picking more and more sprites each time?
  • Actually I don't want to exclude previously selected sprites. I just want to build on the list. So a specific example:

    Sprites 1 overlaps 2 3 and 4

    2 overlaps 5 and 6 (and also 1)

    3 overlaps 7 and 8 (and also 1)

    4 overlaps 9 and 10 (and also 1)

    First I pick sprite 1

    Then I pick sprites 1 2 3 and 4

    If I iterate again I pick sprites 1 2 3 4 5 6 7 8

    and so on and so on.

    I thought the code in my above post would do it, but it won't. Still need help =/

  • Still need a little info. Like are these all the same object? Then what do you want to happen afterwords, as overlapping is a continuous event.

    The problem is that :"sprite overlaps sprite" will look at every sprite instance on the screen, and select those that meet the condition, including any that are overlapping sprites where the pv is already changed.

    +> sprite value = 0

    -> sprite overlaps sprite set value to 1

    Wont work correctly, as there is the possibility that a 0pv sprite will overlap a 1pv sprite.

    Also, overlaps doesn't start with some random sprite. If you want a certain group you will have to come up with way to pick that group.

  • They're all instances of the same object created using Create Object during runtime.

    There will be a bunch of sprites (say, 100). There will be some other objects (say 10), and each of those 10 objects will correspond to one of the 100 sprites (so only 10 sprites will have objects corresponding to them). The function will be called when I start dragging one of the objects. I want to highlight the Sprites so as to indicate to the player that the object may only be dropped on one of those highlighted sprites and not on any other sprites. I want to then be able to check if the object was dropped on one of the highlighted sprites, and get that Sprite's ID and a variety of other attributes. The reason I want it to be recursive is because some objects will have a larger list of sprites they can be dropped on, so think of it as a range. A range of 1 allows an object to be dropped on only on sprites overlapping its corresponding sprite. A range of 2 allows an object to be dropped on sprites overlapping it's corresponding sprite, as well as sprites overlapping those sprites. And the list grows like that for each increase in range.

    Picking the sprite to start from is trivial and works. Creating the range=1 list is also trivial. Growing the list seems to not work if I do it by loop, though I can grow it manually by nesting a bunch of Sprite Overlapping Sprite events as indicated in the 4th post on the thread.

  • Still a little hazy, but I would start with a container and an object that does lists on the sprite that your dragging, unless your dragging one of the instances.

    That way the object being dragged can add all the sprites to its list, then to avoid recursion you can do a loop comparing the overlapped sprites to something say the uid. Something like sprite overlaps sprite system compare sprite uid does not equal list(loopindex)... add uid to list.

  • The problem is that of course the list would change so it can't be in a container.

    Firstly, it's NOT one of the sprites on which I check for overlaps that are being dragged. The sprites on which I check overlaps stay still. Other objects that are on top of those sprites are being dragged.

    Here, let me try ot make it more intuitive

    Imagine a 10x10 grid of square sprites that overlap their neighbors by 1 pixel. I have an object on top of one of those sprites somewhere in the center of the 10x10 grid, and I want to be able to move the object a radius of N. When the player drags the object, the radius of N sprites is highlighted to let the player know where they can drop the object. Ideally a distance expression would work for this above example, but instead of a 10x10 grid, teh sprites are in this case not necessarily equidistant as a function of their range (N) from the object (e.g. instead of physical distance and range, if you think of a network of sprites with varying sizes and locations of overlap, what i want to get is the distance of radius N in connection space)

    When I drop an object, the sprite associated with it would change to the sprite on whcih I dropped it, so if I made a container that wouldn't work. Furthermore, it is possible to drop multiple objects on the same sprites, so although each object is associated with a specific sprite, the converse is not true, such that each sprite is not associated with just one object, it could be associated with multiple objects.

  • Yes, that's exactly what I mean. Why does Grid Filter is Red, Grid overlaps Grid work, whereas my same implementation except using:

    Repeat Range
           Sprite PV IsPicked=1
           Sprite overlaps Sprite  ---> Sprite IsPicked set to 1
                                             ---> Sprite Set filter to red[/code:139omtv6]
    ...not work?  It seems identical.
  • Oh I see, your Repeat is not nested under the picking for the first sprite. Huh, I guess I must not understand how picking works, removing the Repeat from the nesting makes everything work but I don't get why.

    Thanks though

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