[solved] Make a list of values, order them

This forum is currently in read-only mode.
From the Asset Store
Template for scrollable list, fully documented in comment and video
  • Back again already!

    This time I'm trying to make an ordered list out of private variables from different objects. The goal is to make a "ranking" that the player can check, to see how well he/she is doing against some predetermined rivals.

    What I have done so far is storing those values in a hashtable, which works fine. The next part I can't really figure out:

    I want to show a list that has the name of each key along with it's value - the list should then be ordered, so the key with the highest value is on top.

    My attempt: I tried improvising a bit following the example in this thread:

    (for each key: create dummy object, set value.

    for each dummy ordered by value: set text to dummy.Value('Name')& " - " & dummy.Value('Rank')&Newline)

    There are 3 keys in the hashtable, but when I run the layout, it only ever shows the very last key and value.

    Correct my noobish ways! What is a good way of making a list from a hashtable?

  • If you don't mind adding an extra object the list box has a built in sort that will arrange alphanumerically.

    + HashTable: For each key

    -> ListBox: Add line HashTable.Currentkey

  • Or, do your own sort algorithm.

    The following example contains a complete "divide & conquer" sort algorithm (by events) that sorts 3 arrays as if being one. Three one-dimensional arrays hold informations that belong together and are sorted by hiscore:

    http://www.scirra.com/forum/viewtopic.php?f=8&t=8011

  • Phew, suddenly got very busy, and this seemed like something I needed to get the proper time to look at.

    Listbox doesn't seem very customizable when it comes to presentation, so that's why I haven't used it yet.

    But while the Verve example in general looks great and has lots of descriptions, I'm afraid it's still going over my head! I just can't figure it out.

    Also, my rankings list only needs to show the top 10. In your Verve code, you mentioned a simpler way of sorting values, could you maybe explain that one...?

    Sorry and thanks for your help so far

    EDIT:

    Here is my lame attempt so far, based on an example from a memory game I found on these forums:

    http://dl.dropbox.com/u/11716886/hiscoretest.cap

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • There's really nothing wrong with your original method.

    http://dl.dropbox.com/u/666516/hashighstack.cap

  • I tried doing the same as you, just without having to click a button first, but I still can't make it work >_< man, I feel dumb now...

    Here it is so far:

    http://dl.dropbox.com/u/11716886/rankingstest2.cap

    Never would have thought something like ordering after values would have been so difficult for me!

  • There's a few things going on that don't quite work with what you want to do.

    To start your globals are set to 0, so it cant create the objects.

    Now while we're on the dummies, in order to index them correctly you'll need to destroy it on start of layout. You may have not noticed, but I placed the text for the dummy object into a container with the dummy, so you should destroy the text on start as well.

    That brings us to the text. The always event places the text with its container the dummy since if you pick one, you also pick the other, but your going to have some issues aligning the dummy/text to your numbers that way. Plus you will have to do a workaround for the hashtable at some point, as it will not accept duplicate key entries.

  • Finally figured it out Thanks!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)