Same pick operation an arbitrary number of times

For questions about using Classic.

Post » Thu May 26, 2011 2:10 am

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?
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu May 26, 2011 3:33 am

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 =/
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu May 26, 2011 4:45 am

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,
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Thu May 26, 2011 5:01 am

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.

EDIT:

Example

[code:3fp1lo8e]Sprite overlaps sprite
-> Sprite overlaps sprite
-> 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
etc.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Thu May 26, 2011 5:09 am

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.

Edit:
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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Thu May 26, 2011 5:55 am

Hmm, why isn't this code doing it?

[code:g76ca2gi]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?
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Fri May 27, 2011 8:46 am

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 =/
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Fri May 27, 2011 2:45 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Fri May 27, 2011 3:44 pm

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.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Fri May 27, 2011 5:20 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest