How do I Find lowest value in an Array and more

0 favourites
  • 3 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hey,

    i was wondering how i should go about if i want to find the lowest value in an Array, for example, in Array X, Y, Z find the lowest Z first index value.

    Second question is how do i go about finding the lowest neighbour in an Array. for example, once i found the lowest value, how do i search for the lowest neighbour for that lowest value, and then redo the process to find the lowest neighbour to that previously found lowest neighbour (without having the previous cell in the results).

    I have a pretty good idea how to do so with lots of events but it seems rather inefficient and i was wondering if there's a quicker method...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You'll need 4 variables - lowestValue, Xindex, Yindex, and Zindex.

    For each XYZ

    Array.CurValue<lowestValue

    Set lowestValue to Array.CurValue

    Set Xindex to Array.CurX

    Set Yindex to Array.CurY

    Set Zindex to Array.CurZ

    So it will go through the whole array, and whenever it finds a lower value than the last lowest value, it will record that new value and also the XYZ position.

    With that first XYZ index, you can check the neighboring cells by adding or subtracting one from the appropriate index, with similar logic as before.

    If you don't need the index/location of the lowest value, you can do a simple event as follows:

    For each XYZ - Set lowestValue to min(Array.CurValue,lowestValue)

    This might be useful if the value of interest is your first X axis - you can then use Array.IndexOf(lowestValue) to get the position. But that only works on the X axis.

  • Thanks! that's quite an efficient way to go about it!

    Thanks again man, great help.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)