# How do I display the highest element in an array?

Get help using Construct 2

### » Mon Jun 09, 2014 11:00 pm

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?
B
5
Posts: 21
Reputation: 267

### » Tue Jun 10, 2014 10:38 am

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.

arrayhighestlowest.capx
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

### » Tue Jun 10, 2014 5:25 pm

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.

Thanks.
B
5
Posts: 21
Reputation: 267

### » Tue Jun 10, 2014 8:43 pm

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".

arrayfirstvalueof0.capx

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".

highestvalueat0.capx
You do not have the required permissions to view the files attached to this post.
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

### » Wed Jun 11, 2014 10:47 am

Thank you so much. This code is what I needed. You've been very helpful.
B
5
Posts: 21
Reputation: 267