Sort by last character?


  • Coder

    I'm looking for a very simple way to modify existing code. I'm using TinyMUX.

    I have a function that outputs a pipe separated list, like this:

    Borrow Threads (Larceny):2|Correspondence (Academics):1

    Right now I got iter( <list> , %0i, |, %r) and that's outputting onto a character sheet. Is there a simple way I can make it sort by the number at the end, instead of the first letter? I know sort() exists, but best I can see, it's just looking at the first character (all items on this list are attribs on the same object, so dbref doesn't help).


  • Coder

    You could use sortby:

    &d.stat.sort #<dbref>=comp(last(%0, :), last(%1, :))

    then in iter:

    iter(sortby(#<dbref>/d.stat.sort, <list>, |), %i0, |, %r)



  • @Glitch

    Beat me to it. That looks like it'll work (and thanks, I was having trouble figuring out the sort key! I can use this for something I was storing a different way).


  • Coder

    @Glitch said in Sort by last character?:

    &d.stat.sort #<dbref>=comp(last(%0, :), last(%1, :))
    then in iter:
    iter(sortby(#<dbref>/d.stat.sort, <list>, |), %i0, |, %r)

    Not sure if I'm doing something wrong... (#263 is the object the code is on, #279 is my test bit)

    th u(#263/powers.rote,#279) -->

    Borrow Threads (Larceny):2|Correspondence (Academics):1|Isolation (Academics):1|Scrying (Computers):2

    th u(#263/d.stat.sort, u(#263/powers.rote,#279), |) -->

    No output.

    Then when I put the code in the iter() and it outputs the list in the same order, unchanged.


  • Coder

    @Bobotron it's SORTBY(#263/d.stat.sort,u(#263/powers.rote,#279),|)
    Or should be.


  • Coder

    @Seamus

    th SORTBY(#263/d.stat.sort,u(#263/powers.rote,#279),|) -->

    No output.


  • Coder

    @skew on mux or penn or rhost?


  • Coder

    @Seamus Mux.

    I've gotten it figured out, but it's so ugly, it's modestly embarassing.


  • Coder

    @skew

    That d.stat.sort is just used by sortby as a sort of definition of how to do the comparison. The only thing that should be calling it is the sortby function. Also, you should be using get() instead of u() for when you're not evaluating whatever it is you're retrieving.

    So first you need:
    &d.stat.sort #263=comp(last(%0, :), last(%1, :))

    Then powers.rote should probably look something like:
    &powers.rote #263=iter(sortby(%!/d.stat.sort, get(%0/<rotes>), |), %i0, |, %r)
    <rotes> being whatever attribute is holding your power rotes.


  • Coder

    reverse(sort(reverse(<string>),n,|))
    

  • Coder

    @Ashen-Shugar I didn't know about reverse, but that's a neat way to do it.


  • Coder

    Thank you all for the replies. I've not actually gotten around to testing the latest solutions, because I discovered a way to sort my rotes by arcanum in a nice, clean, neat fashion. So, deciding if I want to mess with reverse order.

    It's not exactly code, but anyone have an opinion? Would you rather see rotes (For Mage: The Awakening 2E) alphabetical, or by dot level? They're dot level in the book.


  • Coder

    @skew said in Sort by last character?:

    Thank you all for the replies. I've not actually gotten around to testing the latest solutions, because I discovered a way to sort my rotes by arcanum in a nice, clean, neat fashion. So, deciding if I want to mess with reverse order.

    It's not exactly code, but anyone have an opinion? Would you rather see rotes (For Mage: The Awakening 2E) alphabetical, or by dot level? They're dot level in the book.

    My suggestion? If you're designing this from scratch, allow player customization so that the player can specify what sort method they want for it.

    It should, theoretically, just be a matter of u()ing a different attribute based on the customization the player wants.

    So something like oh....

    ...[u(#obj/SORT.[default(%#/_sheet_sort_method,default)])] ...
    

    Then SORT.DEFAULT is the default sorting method (however you want).
    Then the customized attribute '_SHEET_SORT_METHOD' on the player contains the sort method they want to use (whatever you define)

    Then just u() the #obj/SORT.DEFAULT (or SORT.NUMERICAL, or SORT.ALPHANUM, or whatever) and design your own sorting algos for how you want to sort it on the fly.

    This method also allows adding new sorting algos on the fly without really re-designing any core functionality.


  • Coder

    @Ashen-Shugar Definitely a good idea! But this is not something I'm doing from scratch. I'm trying to wedge some new stuff into existing @Thenomain code. Mostly just making his CofD code work for Mage 2E.

    Thanks.


  • Coder

    This also isn't for customization. It's a report on numerical rank descending. So there's that.


Log in to reply
 

Looks like your connection to MU Soapbox was lost, please wait while we try to reconnect.