Does "Pick Nearest" pick itself?

Discussion and feedback on Construct 2

Post » Wed Aug 07, 2013 9:43 pm

You have 2 instances of the same Sprite.

The following snippet:
Sprite -> Pick Nearest to Self.X, Self.Y


Does it pick itself, or does it pick the other sprite?
B
10
S
3
Posts: 233
Reputation: 1,537

Post » Wed Aug 07, 2013 9:50 pm

Yes they would.
Image ImageImage
B
165
S
49
G
148
Posts: 8,050
Reputation: 97,092

Post » Wed Aug 07, 2013 9:52 pm

I tried another method.
I have 2 instances of Sprite.
One with UID 0 and one with UID 1.

Pick Sprite with UID 0
-> Pick Nearest Sprite to Self.X Self.Y
   -> Set Text to Sprite.UID

It seems to select the sprite with UID 0, in the first pick, and not the sprite with UID with pick 1.


How would you make a sprite pick the nearest other sprite of the same type?Xionor2013-08-07 21:53:25
B
10
S
3
Posts: 233
Reputation: 1,537

Post » Wed Aug 07, 2013 10:06 pm

First you would have to pick one instance, and save its x, and y to a variable, then you would need to make it so that instance is not picked again. So..

On you condition/ trigger picking your object
>- call function("myfunction") set parameter index 0 to object.x, set parameter index 1 to object.y
>-- set object instance variable variable ("dontPickMe") to 1

On function("myfunction")
>-object compare variable("dontPickMe") =0
>--object pick closest to object.variable((myfunction.parameter(0),myfunction.parameter(1))

So basically add a function object to get out of the picking issue.newt2013-08-07 22:08:26
Image ImageImage
B
165
S
49
G
148
Posts: 8,050
Reputation: 97,092

Post » Wed Aug 07, 2013 11:45 pm

@newt

Thanks for the tip. I tried it but it didnt work properly. I'll repost this in the howto section furter and explain my problem better with more detail.Xionor2013-08-07 23:52:21
B
10
S
3
Posts: 233
Reputation: 1,537

Post » Thu Aug 08, 2013 1:50 am

I believe newts example would work, as long as the order is exactly followed. EXCEPT: the first action, make sure to Set the "DontPickMe" to 1 before calling the function.
B
51
S
20
G
10
Posts: 571
Reputation: 9,819

Post » Thu Aug 08, 2013 2:17 am

Check Yann's example in this post:

http://www.scirra.com/forum/pick-closest-not-self_topic48443.html
B
10
S
4
Posts: 133
Reputation: 1,543


Return to Construct 2 General

Who is online

Users browsing this forum: BackendFreak, Digitalarray, Solomon, Tokinsom and 4 guests