Hi I wanted to create a trigger to search for the highest integer amongst a large group of integers. The editor seems to only compare 2 values at a time, is there an easy way of doing this that I've missed? Thanks ♥.
I don't think there is an already written function for that because as far as I know there is no way to pass array parameters to a function. But I'm really by no means an expert, so maybe there is a way.
If you want to get the maximum of say an array that is saved in a global variable you could just write a basic function that returns the maximum value of an unsorted array, which means you have a Local Int Variable "Maximum" that you set to the first entry of the array and afterwards compare it to every other entry of the array and based on the relationship (Maximum > Int[i], Maximum < Int[i]) you set Maximum to Int[i] or you don't.
You can also use a sorting algorithm, Blizzard implemented some of them in the editor already. You can find these in the trigger editor by showing Libraries (ctrl + shift + L) and then navigate to Built-in -> Template -> Algorithms. However a loop as described by Bommes is probably easier, if you just need the maximum.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hi I wanted to create a trigger to search for the highest integer amongst a large group of integers. The editor seems to only compare 2 values at a time, is there an easy way of doing this that I've missed? Thanks ♥.
I don't think there is an already written function for that because as far as I know there is no way to pass array parameters to a function. But I'm really by no means an expert, so maybe there is a way.
If you want to get the maximum of say an array that is saved in a global variable you could just write a basic function that returns the maximum value of an unsorted array, which means you have a Local Int Variable "Maximum" that you set to the first entry of the array and afterwards compare it to every other entry of the array and based on the relationship (Maximum > Int[i], Maximum < Int[i]) you set Maximum to Int[i] or you don't.
You can also use a sorting algorithm, Blizzard implemented some of them in the editor already. You can find these in the trigger editor by showing Libraries (ctrl + shift + L) and then navigate to Built-in -> Template -> Algorithms. However a loop as described by Bommes is probably easier, if you just need the maximum.