Order Reals/Integers from least to greatest

Edward

New Member
Reaction score
2
I am looking for either an in-game function OR Jass script that can order real and integer variables from least to greatest.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, how do you mean, since you always have a set amount of arguments in Jass for a function...
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Can be done by array stack or linked list. But linked list is faster if the entered integer is at middle.
 

Edward

New Member
Reaction score
2
Well, how do you mean, since you always have a set amount of arguments in Jass for a function...

Here is an array of integers:

Array1 = {17, 4, -8, 0, 44, -1, 6}, cardinality = 7,
I want to order these from least to greatest into a new array of of the same cardinality, so:

Array2[1] = -8
Array2[2] = -1
Array2[3] = 0
Array2[4] = 4
Array2[5] = 6
Array2[6] = 17
Array2[7] = 44

I would imagine that it would look something similar to this, except that this doesn't work for some reason.

Set Y = 100,000

For Loop Integer B, 1 to 7 -----
-Loop for Integer A, 1 to 7-----
-Set X = Array1[A]
-If
X < Y
-Then
set Y = X
set Z = A
-Else
Do nothing (end loop for A)

-Set Array2 = Y
-Set Array1[Z] = 100,000 (end loop for B)

EDIT ----------------------
I finally got something to work, but it is very clumsy and it takes way too long. It requires 3 triggers and an extra trigger to check that it worked. I definitely need something better than this since you can NOT use this to accomplish a small task within in a much larger trigger (thus it is useless).

Trigger: 1
Trigger:
  • Initial
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Integer1[1] = 5
      • Set Integer1[2] = 9
      • Set Integer1[3] = -10
      • Set Integer1[4] = 0
      • Set Integer1[5] = 2
      • Set IntegerV = 1


Trigger 2:
Trigger:
  • Order
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Set IntegerY = 10000
      • For each (Integer A) from 1 to 5, do (Actions)
        • Loop - Actions
          • Set IntegerX = Integer1[(Integer A)]
          • Set IntegerZ = (Integer A)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • IntegerX Less than IntegerY
            • Then - Actions
              • Set IntegerY = IntegerX
              • Set IntegerW = IntegerZ
            • Else - Actions
              • Do nothing
      • Set Integer2[IntegerV] = IntegerY
      • Set Integer1[IntegerW] = 10000
      • Set IntegerV = (IntegerV + 1)


Trigger 3
Trigger:
  • Order Stop
    • Events
      • Time - Elapsed game time is 11.00 seconds
    • Conditions
    • Actions
      • Trigger - Turn off Order &lt;gen&gt;


Trigger 4:
Trigger:
  • Display
    • Events
      • Time - Elapsed game time is 14.00 seconds
    • Conditions
    • Actions
      • Game - Display to (All players) for 3.00 seconds the text: (String(Integer2[1]))
      • Wait 3.00 game-time seconds
      • Game - Display to (All players) for 3.00 seconds the text: (String(Integer2[2]))
      • Wait 3.00 game-time seconds
      • Game - Display to (All players) for 3.00 seconds the text: (String(Integer2[3]))
      • Wait 3.00 game-time seconds
      • Game - Display to (All players) for 3.00 seconds the text: (String(Integer2[4]))
      • Wait 3.00 game-time seconds
      • Game - Display to (All players) for 3.00 seconds the text: (String(Integer2[5]))
      • Wait 3.00 game-time seconds
 

meOme

New Member
Reaction score
31
/edit:
After much fixing it works perfectly now.
You can use it multiple times during the map (in case Array1 changes over time), and it even works with multiple numbers, like ( 1, -4, 1, 3, 5, 1, -2 ).

You need these global variables:
Integer_Array1[]
Integer_Array2[]
Boolean_Array[] (initialized with "false")

Put this in your mapheader:
JASS:
function SortIt takes nothing returns nothing
    local integer a = 1
    local integer b
    local integer c
    local integer cardinality = 7

    loop
	exitwhen ( a &gt; cardinality )
	set udg_Integer_Array2[a] = 100000
	set b = 1
	set c = 0
	loop
	    exitwhen ( b &gt; cardinality )
	    if ( udg_Boolean_Array<b> == false and udg_Integer_Array1<b> &lt;= udg_Integer_Array2[a] ) then
		set udg_Integer_Array2[a] = udg_Integer_Array1<b>
		set udg_Boolean_Array<b> = true
		set udg_Boolean_Array[c] = false
		set c = b
	    endif
	    set b = b + 1
	endloop
	set a = a + 1
    endloop
    set a = 1
    loop
        exitwhen ( a &gt; cardinality )
        set udg_Boolean_Array[a] = false
        set a = a + 1
    endloop
endfunction</b></b></b></b>


Now you just need a simple Custom Script in your GUI-Code:
Trigger:
  • a
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Set Integer_Array1[1] = -5
      • Set Integer_Array1[2] = 2
      • Set Integer_Array1[3] = 2
      • Set Integer_Array1[4] = -4
      • Set Integer_Array1[5] = 12
      • Set Integer_Array1[6] = 6
      • Set Integer_Array1[7] = 2
      • Custom script: call SortIt()
      • For each (Integer A) from 1 to 7, do (Actions)
        • Loop - Actions
          • Game - Display to (All players) the text: (String(Integer_Array2[(Integer A)]))

The result:
-5
-4
2
2
2
6
12

PS: It's alright if you don't understand perfectly how it works. I admit it's quite complicated. That's why I made something that you just have to copy&paste. Try to understand it if you like programming. xD
 

Edward

New Member
Reaction score
2
Nice bro that was awesome. I enjoy the challenge of initially doing what seems impossible.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
  • The Helper The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
  • The Helper The Helper:
    Happy Wednesday!
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top