Picking two objects

For questions about using Classic.

Post » Sat May 21, 2011 4:35 am

I have a bunch of sprites, and I'm trying to pick two objects based on the value of one of their variables. The value of the variable, let's call it ID, is different for each sprite. I want to make a condition that will pick two of the sprites, such that if their ID=Value1 OR ID=Value2 they're picked but no other values are picked. It seems like OR does something close to this (e.g. Pick by comparison1 OR Pick by comparison2) however, it doesn't seem to clear previously picked objects the first time.

What I mean is this:

I have 2 objects, Object1 and Object2 with two private variables, Var1 and Var2.
I have 10 Sprites with the private variable ID.

I have the following code:

[code:10btf93t]On mouse over Object ---> Call Function Function1 and Remember


On Function 1
Pick Sprite by Comparison, Sprite.Value('ID')=Object.Value(Var1)
OR
Pick Sprite by Comparison, Sprite.Value('ID')=Object.Value(Var2)
For Each Sprite ---> DebugText set Text Sprite.Value('ID')[/code:10btf93t]

When I put the mouse over Object1, this works fine and I get the ID of both of the sprites that match

Then, If I put the mouse over Object2, the first time, on top of getting the ID of the two correct sprites, I also get the ID of the sprites that match Object1's variables. The second time I put the mouse over Object2 I get only the correct two sprites. This also works in reverse (e.g. if i start with Object2 and then mouseover Object1).

What's going on? I can post the cap but literally the only code involved in the function is exactly what I posted above.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Sat May 21, 2011 5:21 am

I guess I should also say that the above is only a step towards another complicated picking goal.

The end result I want is this:

The 10 sprites are overlapping each other with some sprites overlapping other sprites. The end goal is that when I mouse over Object1, I pick all sprites that overlap BOTH the sprite that corresponds to Object1.Value('Var1') AND the sprite that corresponds to Object1.Value('Var1'). Those 2 sprites themselves should be excluded from the picked list and only the ones that overlap both of them should be included.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Sat May 21, 2011 10:38 am

[quote:h8vc3r33]What's going on?[/quote:h8vc3r33]
The OR condition has issues.

Use the "Pick by evaluate" condition and the "or" expression.
Type something like this for the expression:
Sprite.Value('foo')=1 or Sprite.Value('foo')=2
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Sat May 21, 2011 2:55 pm

Oh great, that works, thanks!. Still having trouble figuring out how to use that now to pick the sprites overlapping those two sprites while excluding the two sprites themselves. Any help would be appreciated!
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Sat May 21, 2011 6:26 pm

[quote:28d59hxy]Still having trouble figuring out how to use that now to pick the sprites overlapping those two sprites while excluding the two sprites themselves.[/quote:28d59hxy]

Add Sprite to a family such as blue
Then do something like this:

+ Sprite: Pick by 'foo'=1 or 'foo'=2
+ Sprite: overlaps Blue : offset (0,0)
+ Blue: Pick by 'foo'!=1 and 'foo'!=2
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Sun May 22, 2011 6:26 am

So if I implemented this correctly, it seems to be picking sprites overlapping either Sprite1 or Sprite2, whereas I wanted to pick sprites that overlap both Sprite1 and Sprite2 simultaneously. While this picks the union of those sprites, I wanted to pick the intersection. Sorry if that wasn't clear.

EDIT:

Just to avoid further confusion, an example is this:

Sprite1 (corresponding to ID=foo1) overlaps Sprites 5 8 9 and 10
Sprite2 (corresponding to ID=foo2) overlaps Sprites 3 4 5 and 9

I want to pick sprites 5 and 9, as they are in both lists.
B
11
S
2
G
3
Posts: 283
Reputation: 1,968

Post » Sun May 22, 2011 7:27 pm

You can use a variable to to achieve that. Pick the sprites around the first selected sprite and set their variable 'select' to 1. Then for the second selected sprite do the same but check if 'select' 1, if it is then that sprite is overlapping both originally selected sprites.

+ Sprite: Value 'foo' Equal to 1
+ Sprite: Sprite overlaps Sprite
+ Sprite: [negated] Sprite: Value 'foo' Equal to 1
-> Sprite: Set 'select' to 1

+ Sprite: Value 'foo' Equal to 2
+ Sprite: Sprite overlaps Sprite
+ Sprite: [negated] Sprite: Value 'foo' Equal to 2
+ Sprite: Value 'select' Equal to 1
-> Sprite: Set filter to Black

You will need to set 'select' back to 0 every time you change what 2 objects are originally selected.
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Mon May 23, 2011 6:03 am

Thanks, that worked
B
11
S
2
G
3
Posts: 283
Reputation: 1,968


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest