How do I find the distance between two of the same objects?

Get help using Construct 2

Post » Wed Sep 23, 2015 4:58 pm

I have a project that makes dungeons.
Once certain width and height parameters are met they are changed to red.
Those are now considered Big Rooms.
Once those Big rooms are created I store the Big Room's UID in an array.

I need to find the three closest Big Rooms to a selected Big Room, then do that for all the following Big Rooms.

I don't know how to pick one instance and find the others inside of a for loop using the UID array.

Then, I want to store the distances in either another array or instance variables with the starting Big Room's UID, UID of the three closest Big Rooms, Then the distance of the three closest Big Rooms.

What the dungeons look like:
Image
Last edited by DurandalCorp on Wed Sep 23, 2015 8:44 pm, edited 1 time in total.
B
5
S
1
Posts: 23
Reputation: 426

Post » Wed Sep 23, 2015 5:17 pm

One way is to add a family that only has that object type and then use that to pick two separate instances.

Another way is to pick one of the instances, save the x and y to variables, and then pick the other and do the calculation.
B
91
S
31
G
103
Posts: 5,234
Reputation: 67,754

Post » Wed Sep 23, 2015 8:23 pm

Am I going about this the correct way?

I want to use 2 for loops to go through the array and find all the three shortest distance Big Rooms.

If it comes across the same UID then skip. If it comes across a UID of 0 then skip.

Once the slots are populated I want to check each slot too see if they are higher than the next. if they are I want them replaced.

Here is a screen shot:
Image
B
5
S
1
Posts: 23
Reputation: 426

Post » Wed Sep 23, 2015 11:33 pm

Here is another crack at it:
Image

While debugging, my value for Closest_Room_Distance_02/Closest_Room_UID_02 and Closest_Room_Distance_03/Closest_Room_UID_03 are the same:
Image
B
5
S
1
Posts: 23
Reputation: 426

Post » Fri Sep 25, 2015 8:25 pm

"I need to find the three closest Big Rooms to a selected Big Room, then do that for all the following Big Rooms."

You can do something like the following. The first event is to select the big rooms. The second event picks only big rooms, loops over each, and then loops over all the other big rooms sorted by distance. The pick by uid condition skips identical big rooms. After that rooms_family will be the the three closest big rooms depending on the loopindex. You can then store the uids any way you like.


rooms width>32
rooms height>32
--- rooms set selected to true

rooms is selected
rooms_family is selected
for each rooms
X [negated] rooms_family pick by uid rooms.uid
for each rooms_family ordered by distance(rooms.x,rooms.y,rooms_family.x,rooms_family.y) descending
--- loopindex = 0
------ "1st closest"
--- loopindex = 1
------ "2nd closest"
--- loopindex = 2
------ "3rd closest"
--- loopindex >2
------- stop loop
B
91
S
31
G
103
Posts: 5,234
Reputation: 67,754


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests