how does sort work?

nworbetan

Member
It's really funny that

I'm sorry, I think I worded this really badly. What I meant was that my ideas about how things should work are laughable. I actually found a couple more reasons why my misunderstanding of sort on a multi-key map was terrible too: a) in that "example" I used, the output of the
Code:
foreach x, y, z in test print_html(x + " " + y + " " + z);
line is the same whether test has been sorted or not, and b) I've actually gone out of my way to use numbers in the first key of a map before because it's an easy way to keep the contents of the map in the order I put them.

Now that y'all have helped beat more sensible ideas into my thick skull though, I like this:
Code:
sort booze_map by -value.d;
foreach x in booze_map print_html("It's been " + booze_map[x].d + " day" + (booze_map[x].d == 1 ? "" : "s") + " since your last " + booze_map[x].b);
a lot more than the nested for loops I was using earlier. It takes a couple extra lines to fill the record in the first place, since (record_name contains key) isn't an option, but having the versatility to do things like "sort booze_map by -value.b.to_int();" makes it totally worth the tradeoff. (Not that putting the more recently created items at the top of the list is especially useful in this situation, it's the principle of it that I like.)
 
Last edited:

slyz

Developer
It takes a couple extra lines to fill the record in the first place, since (record_name contains key) isn't an option
You can do what xKiv proposed earlier: build a first map of records, indexed by whatever you want to use contains on even if that info already exists in the record. You can then transfer it to an int-indexed map for sorting.
Now that y'all have helped beat more sensible ideas into my thick skull though, I like this:
Code:
sort booze_map by -value.d;
foreach x in booze_map print_html("It's been " + booze_map[x].d + " day" + (booze_map[x].d == 1 ? "" : "s") + " since your last " + booze_map[x].b);
a lot more than the nested for loops I was using earlier.
Here is another little shortcut, instead of having to type booze_map[x]:
PHP:
foreach x, rec in booze_map print_html("It's been " + rec.d + " day" + (rec.d == 1 ? "" : "s") + " since your last " + rec.b);
 

fronobulax

Developer
Staff member
little irritating single parenthesis...

Yellow Flag!!!
Baiting the dev team. Ten yard penalty and loss of down.

(And apologies to those who neither know nor care about cultural references to American Football)
 
Top