Announcement

Collapse
No announcement yet.

How do I alphabetize an array of actors based on a string variable?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How do I alphabetize an array of actors based on a string variable?

    I'm working on an inventory system similar to Skyrim/Dragon Age/Most western RPGs. The items that can be picked up consist of an actor blueprint that has an array of various information in it (name, weight, sell value, item class, parent class, etc.). That actor is stored in an array when a player interacts with it. The array is then checked for duplicates (minus armor and weapons) and stores them into a different array. The stacked item array is then broken open, parent class (read: type--weapon, armor, consumable, etc--of item) is read, and it's assigned to a UMG scroll box widget. The system works quite well except for one annoying bit, the items are listed in the UMG inventory boxes in the order that they were picked up instead of alphabetically.

    So, I ask you, my fellow developers, any ideas on how to actually make the items appears alphabetically? The only thing I can think of (involving blueprint) is a lot of forloopwithbreaks that break open the array of item information, and do if statements with the "String starts with" command... that would be a lot of loops since you'd have to break it down into does it start with A? Yes? OK, is it AA? No? How about AB? AC? and on and on... then when it finds AG is it AGA? AGB? I'm sure the point is made.

    Any thoughts?

    #2
    Hello,
    You can compare letters of words (need to break string and compare first one then second and arrange names using a similar method as Mhousse1247
    thread : https://forums.unrealengine.com/show...l=1#post274398

    Or you can set an id based on a prepared name arranged array (external too) and use it to arrange and avoid compare loop (but this one needs to be rectify each time you change a name, add a new one)

    Comment


      #3
      Ah, so I make a new structure (FAlphabetizedList) that contains a data table of strings that are the same name as the inventory item names then run a ForEachLoop of the original inventory array that has a ForEachLoopWithBreak (in the ForLoop) that breaks open the FAlphabetizedList structure (variable) and does a string == string check, if it passes add it to a SortedInventoryArray (using the same structure as the original inventory array) then break and let the original ForLoop continue with every item in the original inventory array?

      I'm not dreadfully concerned about performance as the game is paused while all this is being parsed but I would think that method would be less processor intensive than a few hundred if statements being run for every index in an array.

      Comment


        #4
        Yes, the idea is to "find" in second array value of index of the name and store it (or setting this value directly in your struct when you create it with an external array, for example you have a spreadsheet and arrange it to have your index set on name then import it as csv.), then doing the loop system with the example shown before, replacing length by integer.
        Last edited by Fen; 05-06-2015, 04:12 AM.

        Comment


          #5
          Finally had the time to sit down and try this out.

          I set up a data table and use GetDataTableRowNames to output the array of row names, feed that into a foreachloop that scans the inventory for the matching name, if that returns true it then checks the equipped status. If that returns true then it adds it to a local array. Upon completion I run another foreachloop that checks for a matching name but tests to see if the item is not equipped. If it's not it adds it.

          Works perfectly, much obliged sir or ma'am.

          Comment

          Working...
          X