[solved] Make a list of values, order them

For questions about using Classic.

Post » Sun Mar 27, 2011 2:46 pm

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:
viewtopic.php?p=38394#p38394
(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?
B
10
S
3
G
3
Posts: 110
Reputation: 2,206

Post » Sun Mar 27, 2011 3:05 pm

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
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Sun Mar 27, 2011 8:47 pm

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:
[url:17ue5akc]http://www.scirra.com/forum/viewtopic.php?f=8&t=8011[/url:17ue5akc]
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Sat Apr 16, 2011 11:12 am

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
B
10
S
3
G
3
Posts: 110
Reputation: 2,206

Post » Sat Apr 16, 2011 4:48 pm

There's really nothing wrong with your original method.
[url:1mcf9rnb]http://dl.dropbox.com/u/666516/hashighstack.cap[/url:1mcf9rnb]
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Sun Apr 17, 2011 10:12 am

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!
B
10
S
3
G
3
Posts: 110
Reputation: 2,206

Post » Sun Apr 17, 2011 3:41 pm

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.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Sun Apr 24, 2011 8:59 am

Finally figured it out :) Thanks!
B
10
S
3
G
3
Posts: 110
Reputation: 2,206


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests