Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Help with Sorting an Array in a Blueprint?

Every time I try to connect the exec from the sequence of nodes I have to sort my array, my game crashes.

The array has 5 elements, index 0 being of highest value and index 4 being of lowest value.

I want to write in the integer variable value ("ST") to the index's value that is less than the value of ST, but only the index that is one index higher than the value that is larger than the ST value.


ST = 76

Array is set at:

index 0 ---> 100

index 1---> 75

index 2---> 50

index 3---> 30

index 4---> 10

Only substitute index 1 with ST value (76), not index 2 - 4

Could someone help me out?

I have tried While Loop, Add, MaxOfIntArray, RemoveIndex, other variations of exchanging an index value w/ a variable's value.

Product Version: UE 4.9
more ▼

asked Dec 13 '15 at 09:44 PM in Blueprint Scripting

avatar image

170 47 49 60

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

The node that fixed my problem was Insert. A very useful node, if you have an array with 5 elements it will insert the value into the index you give it and push all other values (of higher index) up an element in the array. So even if you get a value stored to array element 5 it will not show up in the array because 0-4 will have been set, one of those indexes with your desired value. It basically made it so I can set a value and not have to worry about any numerically sorting techniques to replace the value that was replaced with the index above it if it was still of higher value (when trying to sort the array, 0 as highest 4 as lowest).

more ▼

answered Dec 14 '15 at 06:19 PM

avatar image

170 47 49 60

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

If I have understood the algorithm correctly and assuming you have the values ordered descending in the array. You go from the bottom/last (index 4) and check if its higher.

if it is higher than the value 76 > (10) then store that index in a temporary variable e.g. HighestValidIndex = 4.

then you go to the next index (3) is it higher? 76>30, yep, HighestValidIndex=3

next index (2) is it higher? 76>50, yep, HighestValidIndex=2

next index (1) is it higher? 76>75, yep, HighestValidIndex=1

next index (0) is it higher? 76>100, nope!, Break the loop and store value of ST in the HighestValidIndex.(1)

so you get index 1 = 76.

more ▼

answered Dec 13 '15 at 10:35 PM

avatar image

726 36 15 42

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hello, you may try to convert Buuble Sort algorithm into blueprints. Lets start from sample code:

 void bubbleSort(int arr[], int n) 
    int i, j; 
    for (i = 0; i < n-1; i++)       
        // Last i elements are already in place    
        for (j = 0; j < n-i-1; j++)  
            if (arr[j] > arr[j+1]) 
               swap(&arr[j], &arr[j+1]); 

This is C++ now let's convert it into blueprint.

alt text

Hmm... screen size is to small... let me split it to parts, maybe it will help you.

alt text

Here we have two nested loops as it is in code refrence. Then we do this: alt text

I Sort my table of saves by it's creation date. Maybe this solution will help you.

bubble-sort.png (114.3 kB)
bubble-sort1.png (92.8 kB)
bubble-sort2.png (156.0 kB)
more ▼

answered Jul 11 '19 at 06:52 PM

avatar image

1 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question