Loop through UIDs

Get help using Construct 2

Post » Thu Mar 14, 2013 11:29 pm

I've been reading through this thread about UIDs and selection, but I'm not sure how I would loop through all the UIDs.

In particular, I am trying to determine the distance from an object to every instance of another object and then save the closest one. This involves looping through every UID of the object and checking the distance.

Does anyone have any idea how to do this?
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Thu Mar 14, 2013 11:38 pm

So basically you're saying you need a condition to pick the nearest, or farthest instance based on an xy?

Something like the pick by uid condition, but shall we say right next to it?
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Thu Mar 14, 2013 11:50 pm

I might have misunderstood therefore I might be over-simplifying..

But there's already a "pick nearest" condition you could use?

Cond: myObject Pick Nearest X=SourceObj.X Y=SourceObject.Y

Would return nearest "myObject" to a source object.
B
20
S
6
G
2
Posts: 157
Reputation: 3,109

Post » Thu Mar 14, 2013 11:56 pm

Why not use the 'pick nearest' condition?
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,518

Post » Fri Mar 15, 2013 1:29 am

Does that work for multiple instances?

Find Path to Object.X, Object.Y doesn't work if that object has multiple instances. Does 'pick nearest' work for instances?

If so, then perhaps this is simpler than I thought!
Project Lead of Zems Online Card Game

Producer at Impulse Limited
B
18
S
6
G
3
Posts: 677
Reputation: 5,194

Post » Fri Mar 15, 2013 6:13 am

[QUOTE=Excal] Does that work for multiple instances?

Find Path to Object.X, Object.Y doesn't work if that object has multiple instances. Does 'pick nearest' work for instances?

If so, then perhaps this is simpler than I thought![/QUOTE]

In case of event "Player: Pick nearest Enemy"
pick nearest picks the instance of the Enemy object, that is closest to the picked player object. So yes, it would work in your case to pick the nearest enemy. :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests