0 Favourites

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

  • 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

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,137
karshinkoff's avatar
karshinkoff
Unread hot topic
78 10,775
Josek5494's avatar
Josek5494
Unread hot topic
0 Favourites
C2 Data Editor (Tools)
75 11,160
AnD4D's avatar
AnD4D