• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

[General] How to easily filter integers?

Status
Not open for further replies.
I use Math - Max, but I doubt that it is really working, because I wonder is this function picking teh variables or just their integers?

I'm trying to easily isolate the integer variable(they are 4 here) that has the biggest number and work with it. Any ideas?

for example:
  • Set Round_Time = Round_Time_R[(Max((Max(_TPVote[1], _TPVote[2])), (Max(_TPVote[3], _TPVote[4]))))]
Is this setting the variable or the number of it?
 
Last edited:
  • Set Max = 0
  • If (Var[0] greater than Max) then
    • Set Max = Var[0]
  • If (Var[1] greater than Max) then
    • Set Max = Var[1]
  • If (Var[2] greater than Max) then
    • Set Max = Var[2]
  • If (Var[3] greater than Max) then
    • Set Max = Var[3]
You can also store the index instead of the max value.

If you have more numbers you can look into the many sorting algorithms.
 
Level 12
Joined
May 22, 2015
Messages
1,051
This should work, but what is it supposed to do? You are using the max number out of those 4 as the index to pull from the array Round_Time_R. I don't know if that array is set or not.
 
Level 39
Joined
Feb 27, 2007
Messages
5,024
Is this setting the variable or the number of it?
Integers (and all primitives, aka not handles) returned from any function in JASS are just the value of the variable, not a pointer to where the value is stored (like you want).

The only way to do something like this is to use an array and return the index of the max value rather than the value itself. Basically what TriggerHappy posted but instead of Max = Var[1], etc. do Max = 1 and then to change it later do like Var[Max] = Var[Max] - 1.

Other solution would be to use a struct with overloaded > and < operators to determine which one is the max. But it seems you're using GUI.
 
Status
Not open for further replies.
Top