How do I display the highest element in an array?

0 favourites
  • 5 posts
From the Asset Store
🙌 Element Magic Hit Sound Pack comes with 805 high-quality sound effect
  • Hi,

    Newbie here and so this might be a silly question.

    I have an 2-d array where each element can have a value from 0 to 5. Now I want the game to be able to select the highest element whose value is not a 0 and display it as a text.

    Is there any way to do that?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here is an example of how you can find the highest, lowest, total & average value of an array. Numbers are between 0-5 but are decimal you can easily change it to use whole numbers.


  • Thanks so much for your reply.

    But this isn't what I wanted. I am very sorry that I didn't explain myself well. English isn't my mother-tongue.

    What I want is something like this - say in an 1 dimensional array, the elments are 1,2,1,3, 5, 0, 0, 0

    So the highest element with 0 as its value is 6.

    This is what I want to be able to do - a way for the game to return the value of 6.


  • I've made 2 examples because you're sort of describing 2 different things. I know English isn't your first language so no problem.

    In your description you are finding the first position with a value of 0. Don't forget Arrays are "0" based so the 1st element in an array is "0" not "1".

    So in your example 1,2,1,3,5,0,0,0 the first value of "0" would be "5".


    If you did want to find the last/highest element of "0" in the array so 1,2,1,3,5,0,0,0 it would be "7".


  • Thank you so much. This code is what I needed. You've been very helpful.

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