# How do I pick furthest cell with specific data in the array

Get help using Construct 2

### » Sat May 07, 2016 7:12 pm

Hi,

Working on level generator and I am looking for a way to pick furthest as well as nearest specific data in array from a selected point. Any clue how to get this done? thanks
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
93
S
30
G
22
Posts: 1,987
Reputation: 20,203

### » Sat May 07, 2016 7:27 pm

You could do it with a second array we'll call "list" and has a size of (0,3,1).

So you'd first loop over your array and check if any spot is equal to that certain value. If it is then make the list one longer and store the distance, and the current x and y in the array.

After that use the sort action on list and the first value will be the closest and the last will be the furthest.

Every tick
--- set list size to (0,3,1)

Array: for each xy
Array: current value=certainValue
--- list push 0 front
--- set list at (0,0) to distance(X,y, array.curx, array.cury)
--- set list at (0,1) to array.curx
--- set list at (0,2) to array.cury

Every tick
--- list: sort

Then the closest X and y would be:
List.at(0,1)
List.at(0,2)

And the furthest:
List.at(list.width-1,1)
List.at(list.width-1,2)
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674