I'm sure this is easy but I can't seem to find an easy solution so I was wondering if anyone can answer this real quick.
I have an array of 8 integers. I'm making a dialog with each of these integers displayed but I want to change the color of the highest integer. What's the quickest and easiest way to find the highest integer in the array for use in the following If-Then Statement?
If Integer is Highest (this obviously is subject to change based on the solution, but you get the idea)
Then Color of Dialog Item is Red
Else Color of Dialog Item is White
Blizzard implemented several different sorting algorithms to sort all values in an array by their value. They implemented things like Bubblesort, Quicksort etc (some more information here)
You can basically pick one of those and sort your array by size, the first/last value in the array will be the highest one (depends on sorting order)
You can find the algorithms in the trigger editor, library Built in/Template/Algorithms (make sure to show libraries in your view options)
What the previous posters said is correct as well. You can simply compare all values to get the highest one. But since the sorting algorithms are already present, you could use them as well ;)
they do require more processing power then just pulling out the highest value..... now if you intend to come back and find the next highest and then the next highest.... then you do want to use a sort ......
generally you would use a second variable to hold the "sorted" array
Only bools, ints, reals, strings (texts?) and object pointers can be passed as arguments to functions. Arrays as well as structs aren't referenced by pointers like every other object in the game is. You will get a 'bulk copy unsupported' error, because the function will try to duplicate the whole array which is not allowed.
The same happens if you try to set one array to equal another.
A sorting algorithm .... changes the order of the values in an array to be in order of min-max or vice versa
what you want to do is just a simple loop through all the values to determine the highest value i think.
SouLCarveRR is correct here. The original question was not how to sort, but rather simply to find the largest value.
I have not messed with arrays in the editor, but if they do not have a built-in equivalent of a max() function that returns the largest value in an array, the all you really need to do it yourself is make a Function and
Function: MaxIntegerInArray
(assuming parameter: an array of integers named integerArray)
Local variable: largestFoundInteger = integer (default value 0)
Local variable index
For Each Integer (index) from (0) to (length of (integerArray)) incrementing by 1 {
if you cant pass arrays..... then you just have to write a hard coded function to handle your array.... meh
although..... if theres prebuilt sort functions in sc2 .... how do those work with out passing an array to them....
IIRC they're only templates. They probably made them back in the time where you COULD pass arrays, and now you could only copy them and use them inside a hard coded function like you said..
They don't even pass around any parameters, it's basically sort my global array.
You're supposed to copy/paste the template as a starting point if used.
I'm sure this is easy but I can't seem to find an easy solution so I was wondering if anyone can answer this real quick.
I have an array of 8 integers. I'm making a dialog with each of these integers displayed but I want to change the color of the highest integer. What's the quickest and easiest way to find the highest integer in the array for use in the following If-Then Statement?
If Integer is Highest (this obviously is subject to change based on the solution, but you get the idea) Then Color of Dialog Item is Red Else Color of Dialog Item is White
You could try the built-in sorting algorithms ;)
Forgive my stupidity, but what/where are those?
A sorting algorithm .... changes the order of the values in an array to be in order of min-max or vice versa
what you want to do is just a simple loop through all the values to determine the highest value i think.
@siege911
int highest = array[0];
for (1 through 7)
if (highest < array[i])
highest = array [i];
then you can do...
If Integer is Highest Then Color of Dialog Item is Red Else Color of Dialog Item is White
Blizzard implemented several different sorting algorithms to sort all values in an array by their value. They implemented things like Bubblesort, Quicksort etc (some more information here)
You can basically pick one of those and sort your array by size, the first/last value in the array will be the highest one (depends on sorting order)
You can find the algorithms in the trigger editor, library Built in/Template/Algorithms (make sure to show libraries in your view options)
What the previous posters said is correct as well. You can simply compare all values to get the highest one. But since the sorting algorithms are already present, you could use them as well ;)
Thanks. I'll look into that.
The only thing about using the sorting.... is
they do require more processing power then just pulling out the highest value..... now if you intend to come back and find the next highest and then the next highest.... then you do want to use a sort ......
generally you would use a second variable to hold the "sorted" array
so
SortedArray = ( SortMethod(UnsortedArray,any needed parameters))
Then you loop through the sorted array to get the values in the order you want to handle them in
Only bools, ints, reals, strings (texts?) and object pointers can be passed as arguments to functions. Arrays as well as structs aren't referenced by pointers like every other object in the game is. You will get a 'bulk copy unsupported' error, because the function will try to duplicate the whole array which is not allowed.
The same happens if you try to set one array to equal another.
SouLCarveRR is correct here. The original question was not how to sort, but rather simply to find the largest value.
I have not messed with arrays in the editor, but if they do not have a built-in equivalent of a max() function that returns the largest value in an array, the all you really need to do it yourself is make a Function and
Function: MaxIntegerInArray (assuming parameter: an array of integers named integerArray)
if you cant pass arrays..... then you just have to write a hard coded function to handle your array.... meh
although..... if theres prebuilt sort functions in sc2 .... how do those work with out passing an array to them....
IIRC they're only templates. They probably made them back in the time where you COULD pass arrays, and now you could only copy them and use them inside a hard coded function like you said..
There aren't any pre-built sort functions, they are templates since arrays cannot be passed around nor can you determine the size of an array.
There's isn't a max for collections, but the plain old min, max is there.
@s3rius: Go
They don't even pass around any parameters, it's basically sort my global array. You're supposed to copy/paste the template as a starting point if used.
@Kueken531: Go
OMG you don't know how much that will help me. Never knew that there were built in libraries.