Are you sure about that? I admit I don't entirely understand the syntax for sort.
Yes, I'm sure, and I'll explain how I think about sort.
Firts, the syntax for sort is:
sort map by expression
map: is any map that associates keys (indices) with returned values
expression: is an expression evaluated for each item in map
To do the sort, mafia considers each item in the map one at a time and computes the expression for that item. Then the result of the expression for that item determines where it gets sorted to. To build the expression you have access to two 'special' variables.
index: refers to the key of the item under consideration
value: refers to the value of the item under consideration
In this case, map is:
item [int] options
so index refers to the int key and value refers to the returned item.
and the proper expression is:
-maxval[value]
which looks the item up in the maxheal map to get the integer maxhp/mp, and then takes the negative so big values become small ones.
If you instead did the sort inside the hp section, you could directly get away with this:
sort options by -heal[value].maxhp;
without needing the second maxval map. It just looks up the item directly in the heal map, grabs the maxhp field, and then reverses the order.
Does that make more sense?
Cheers, juyes
Edit: ninja'd, because it looks like you figured it all out before my message, but it may help other people