MU Soapbox

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Muxify
    • Mustard

    Sort by last character?

    MU Code
    6
    15
    3545
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • skew
      skew last edited by

      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).

      1 Reply Last reply Reply Quote 0
      • Glitch
        Glitch last edited by

        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)

        Bobotron skew 2 Replies Last reply Reply Quote 2
        • Bobotron
          Bobotron @Glitch last edited by Bobotron

          @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).

          ZekeTheG33k 1 Reply Last reply Reply Quote 0
          • skew
            skew @Glitch last edited by skew

            @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.

            1 Reply Last reply Reply Quote 0
            • ZekeTheG33k
              ZekeTheG33k @Bobotron last edited by

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

              Pay no attention to me. I'm old, jaded and generally unfriendly. I am prone to fits of stupidity, but I am still unique, just like everyone else. ~~ Current President of the Anti-Faraday fan club.

              skew 1 Reply Last reply Reply Quote 0
              • skew
                skew @ZekeTheG33k last edited by

                @Seamus

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

                No output.

                ZekeTheG33k 1 Reply Last reply Reply Quote 0
                • ZekeTheG33k
                  ZekeTheG33k @skew last edited by

                  @skew on mux or penn or rhost?

                  Pay no attention to me. I'm old, jaded and generally unfriendly. I am prone to fits of stupidity, but I am still unique, just like everyone else. ~~ Current President of the Anti-Faraday fan club.

                  skew 1 Reply Last reply Reply Quote 0
                  • skew
                    skew @ZekeTheG33k last edited by

                    @Seamus Mux.

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

                    Glitch 1 Reply Last reply Reply Quote 0
                    • Glitch
                      Glitch @skew last edited by Glitch

                      @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.

                      1 Reply Last reply Reply Quote 0
                      • Ashen-Shugar
                        Ashen-Shugar last edited by Ashen-Shugar

                        reverse(sort(reverse(<string>),n,|))
                        
                        Glitch 1 Reply Last reply Reply Quote 3
                        • Glitch
                          Glitch @Ashen-Shugar last edited by

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

                          1 Reply Last reply Reply Quote 0
                          • skew
                            skew last edited by

                            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.

                            Ashen-Shugar 1 Reply Last reply Reply Quote 0
                            • Ashen-Shugar
                              Ashen-Shugar @skew last edited by

                              @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.

                              skew 1 Reply Last reply Reply Quote 0
                              • skew
                                skew @Ashen-Shugar last edited by

                                @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.

                                1 Reply Last reply Reply Quote 0
                                • Thenomain
                                  Thenomain last edited by

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

                                  “If you wish to make an apple pie from scratch, you must first invent the universe.”
                                  ― Carl Sagan, Cosmos

                                  1 Reply Last reply Reply Quote 0
                                  • 1 / 1
                                  • First post
                                    Last post