How can i take the highest number?

Started by GuerraReturns on

Topic category: Help with MCreator software

Joined Jan 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How can i take the highest number?
Tue, 11/17/2020 - 01:29 (edited)

Sorry for bad english.

I have 13 Numbers, i need take the highest number, how i can do?
For example: 1,5,3,4,7,1,2,9,3,4,6,2,3

Well, here the higher number is "9", but how i can write this inside the procedure? (obviusly numbers are random)
This is for a vote system for maps.

I have 13 maps, i need select the map by voting (1 vote, +1 Global variable for the map)

I ALREADY WRITE THIS: (map 1 > map 2 and map 1 > map 3 and map 1 > map 4 etc...) for all maps (and the game need calculate it in 1 tick.............), but is too heavy for the mod and not change my "SelectedMap" global string variable to the map name...

Any idea?

Edited by GuerraReturns on Tue, 11/17/2020 - 01:29
Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Some code like this should…
Tue, 11/17/2020 - 12:47

Some code like this should work:

double largestValue = 0;
double largestIndex = 0;
double currentIndex = 0;
		
List<Integer> values = new ArrayList<Integer>();
values.add(1); // first value
values.add(2); // second value
values.add(3); // third value
values.add(4); // and so on
	
while (currentIndex < values.size) {
	int currentValue = values.get(currentIndex);
	if (currentValue > largestValue) {
		largestValue = currentValue;
		largestIndex = currentIndex;
	}
	currentIndex++;
}

At the end of the while loop, the map number you want will be in largestIndex