 |
Davos Adept
Joined: 30 Jan 2003 Posts: 228 Location: USA
|
Posted: Wed Oct 08, 2003 7:55 pm
Sorting |
I have output like this
Pinewood vial213792 a caloric salve 59 41
Cherry wood vial190477 a salve of mending 6 72
Chestnut vial151007 an elixir of immunity 45 58
Redwood vial268855 an elixir of levitation 32 45
Birchwood vial122268 a salve of restoration 44 91
Chestnut vial131629 an elixir of frost 47 91
Redwood vial199861 a salve of mass 32 78
the third column is what I want to sort by, basicly I need to add all the Vial#'s to a list and then sort them by the third column
any simple way fo doing this? |
|
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Wed Oct 08, 2003 10:46 pm |
quote: Originally posted by Davos
I have output like this
Pinewood vial213792 a caloric salve 59 41
Cherry wood vial190477 a salve of mending 6 72
Chestnut vial151007 an elixir of immunity 45 58
Redwood vial268855 an elixir of levitation 32 45
Birchwood vial122268 a salve of restoration 44 91
Chestnut vial131629 an elixir of frost 47 91
Redwood vial199861 a salve of mass 32 78
the third column is what I want to sort by, basicly I need to add all the Vial#'s to a list and then sort them by the third column
any simple way fo doing this?
I am guessing that by third column you mean the first numeric column.
#CLASS VialCapAndSort
#VAR Vials {} {}
#VAR ThirdColumn {} {}
#TR {something that indicates start of vial display} {Vials="";ThirdColumm=""}
#TR {^* vial(%d)%s*%s(%d)%s%d$} {#ADDKEY Vials {%replace(%format("&02n",%2)," ","0")} {%1};#ADDITEM ThirdColumn {%replace(%format("&02n",%2)," ","0")}}
#TR {something that indicates end of vial display} {ThirdColumn=%sort(@ThirdColumn);#NOOP Sorted, now what}
#CLASS 0
This assumes that my guess of column will be unique for each vial, if it isn't then the script has to be ammended. Of course portions of this script should further be controlled with #T+ and #T-, but you left a lot out in your request. |
|
|
|
 |
Davos Adept
Joined: 30 Jan 2003 Posts: 228 Location: USA
|
Posted: Wed Oct 08, 2003 10:56 pm |
Let me expand further, first off yes, the first numeric column is what I want to sort by, the forum didnt keep the formatting on it too well
what im trying to achieve is putting the first numeric column in decending order, the highest number in this column could be 60 and the lowest number could be 0 and yes there could be several of each number.
How I could accomplish is by putting the vials into my pack with the syntax -Put vial in pack- the first vial put into my pack will be the first vial taken out if I use the syntax -take vial from pack-
SO what i want to do is put all the vials in my pack starting with the ones that say 60 (all of them) then check for the next lowest level and put those all in and so on... The easiest way I see in doing this is imputing them into some type of string variable in decending order, Vials with the number 60 being first and on down and then doing put vial# in pack for each vial in the string which is rather simple, but the issue I have is getting them into the string variable in the correct order, if this is even the best way to do it. After I get this to work what I would like to do is add in something that would only sort if they were out of order, that seems rather simple tho just assign the third column to a variable and check to see if the one above it is lower or the same as the current triggered one, if it isnt it would then need to sort. Hope this helps. |
|
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Thu Oct 09, 2003 3:52 am |
Ok, you don't really need a sort, you just have to record info about the vials into appropiate numbers, so you can pack them in a specific order. Easiest way to do this is with a record variable containing string lists.
#CLASS VialCapAndSort
#VAR Vials {} {}
#VAR ThirdColumn {} {}
#TR {something that indicates start of vial display} {Vials="";ThirdColumm=""}
#TR {^* vial(%d)%s*%s(%d)%s%d$} {ThirdColumn=%db(@Vials,"%2");ThirdColumn=%additem("%1",@ThirdColumn);#ADDKEY Vials {%2} {@ThirdColumn}}
#TR {something that indicates end of vial display} {#ECHO %expanddb(@Vials,%cr,":")}
#CLASS 0
This just estblishes the data structure. You can use "#LOOP 60,1", #IF, #FORALL, and %db to build a script to put them all in the pack in the right order. If you need help with it just ask. |
|
|
|
 |
Davos Adept
Joined: 30 Jan 2003 Posts: 228 Location: USA
|
Posted: Thu Oct 09, 2003 3:58 am |
Yes I do believe I do, let me get this straight, with your above example is it somehow attaching %1 (the number directly after the vial) with the number to the right of that in what we are calling the third column? because when they are packed/unpacked they will havta be referenced using %1 not %2, the word vial in front of the number is not necessary just the %1 afterwards, which is why I hardcoded vial into the pattern, but yes how would I then use LOOP to put all these vials into my pack starting with the ones where %2 = 60 first and then going down to 0??
|
|
|
|
 |
Davos Adept
Joined: 30 Jan 2003 Posts: 228 Location: USA
|
Posted: Thu Oct 09, 2003 8:17 am |
ok here is my full mud output, I took out most of the vials from the middle to save space
Vial Elixir Sips Months Left
--------------------------------------------------------------------
Pinewood vial213792 a caloric salve 59 41
Cherry wood vial190477 a salve of mending 6 71
Chestnut vial151007 an elixir of immunity 45 57
Redwood vial268855 an elixir of levitation 32 45
Birchwood vial122268 a salve of restoration 44 90
Zebrawood vial223596 an elixir of mana 60 124
Zebrawood vial223631 an elixir of mana 60 124
Zebrawood vial223690 an elixir of mana 60 124
Zebrawood vial223692 an elixir of mana 60 124
Zebrawood vial223699 an elixir of mana 60 124
Cedarwood vial85007 empty 0 57
3198h, 2047m ex-
heres my settings, the BOLD is what Ive changed since what you told me last post.
#CLASS {VialCapAndSort}
#VAR Vials {} {}
#VAR ThirdColumn {} {}
#TRIGGER {Vial%sElixir%sSips%sMonths%sLeft} {Vials="";ThirdColumm=""}
#TRIGGER {^* vial(%d)%s*%s(%d)%s%d$} {ThirdColumn=%db(@Vials,"%2");ThirdColumn=%additem("%1",@ThirdColumn);#ADDKEY Vials {%2} {@ThirdColumn}}
#TRIGGER {%dh,%s%dm%s} {#ECHO %expanddb( @Vials, %cr, ":");#loopdb @vials {#IF (%db( @vials, 60)) {#FORALL %val {#SHOW %i}}};#T- VialCapAndSort}
#CLASS 0
I know im not doing this right but it was the best I could come up with after trying many combinations, the only thing included here is a Alias that turns this class on but its not important so its not here...Any help is appreciated, and MAYBE this time Ill remember to put my UserName and Password in at the top and not Loose this entire post like I just did a few minutes ago...Ugh! |
|
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Thu Oct 09, 2003 10:28 pm |
Sorry for the delay in replying. I woke up a little late this morning. Anyhow,
#TRIGGER {%dh,%s%dm%s} {#loop 60,1 {#IF (%db(@Vials, %i)) {#FORALL %val {#SHOW %val-%j}}};#T- VialCapAndSort}
Now if you need to get and put them into some container it shouldn't be too hard.
As to only redoing those that need sorting. I would say it would be better to just track the actual sips value, and have the script pick the appropiate vial. This would require you change the capturing trigger so it recorded what the vial is used for as key and vial numbers as value, then a second record with vial numbers as key and sips left as value. You would then check those records and decide which vial to actually grab. At least that is what I would do, but if you really want to be able to resort the whole thing in a shorter fashion, then you need to keep the third column number in another variable (this could be done by use of a control field in the current vials record variable). You would compare that as > the current capture, and only when it is does it need to resort the vials. At that point you set a resort field to that value then use that for the high number of the #LOOP. If you can't figure what I mean then I could rewrite the thing into a new script for you. |
|
|
|
 |
Davos Adept
Joined: 30 Jan 2003 Posts: 228 Location: USA
|
Posted: Thu Oct 09, 2003 10:41 pm |
Ok NOW I see how you did it and can do do it I think It will be late this evening before I can test, but in the meantime, If it would not be much trouble to show me how I could compare the sip for one line to the one above it and then if it is not in order then resort them? also If I wanted to sort them starting at 0 first I would just change the above I would just change the #LOOP to 1,60 or just #LOOP 60 right? Because now that I think about it, it would be more practical for me to have the lowest sip levels at the top of the list rather than the bottom, Thanks Again
|
|
|
|
 |
Davos Adept
Joined: 30 Jan 2003 Posts: 228 Location: USA
|
Posted: Fri Oct 10, 2003 7:57 am |
Another issue Im having is
#loop 60,1 {#IF (%db( @Vials, %i)) {#FORALL %val {#SHOW %val-%j}}}
Is not working at all, even with @vials full of the right info and then i copy and paste the above line into the command line it still doesnt produce any results, Im not sure why, because it should.
Also...
#ECHO %expanddb( @Vials, %cr, ":")
which we were using to test to make sure @vials filled correctly is taking several second (15-45) to #ECHO after the list of vials is ran, is this simply because it takes that long to process all the information? Thanks |
|
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Sat Oct 11, 2003 1:44 am |
Hehe, my brain cells got crossed. %val is only populated with #LOOPDB. The corrected line would be, also expanded the loop to cover 0:
#loop 60,0 {#IF (%db( @Vials, %i)) {#FORALL %db(@Vials,%i) {#SHOW %i-%j}}}
If you want to reverse the order to be 0 to 60 simply switch the loop to 0,60. The more I thought about it, the more I figured comparing sips to eliminate getting and putting of vial that do not need to be moved, would be a very large amount of trouble. And considering that most mud provide an all modifier for get it is probably not worth it. I would suggest if you can just put new vials into a different container and when you have a chance run the sort to store them properly.
I know I haven't really been handing you solutions thoughout this thread; it is just that I see you are starting to answer other people's questions in the forum. So that makes me think you just need a push in the right direction, and you will figure it out. It has been my experience that the problems I have to think about to solve, as opposed to those that someone solves for me, tend to be remembered a little better. Might just be me. Anyhow, "you got questions...we have answers." |
|
|
|
 |
Davos Adept
Joined: 30 Jan 2003 Posts: 228 Location: USA
|
Posted: Sat Oct 11, 2003 2:30 am |
Yes Im thinking myself that it would be easier to put this all in a class, which is allready the case and just turn the class on when I see that the list needs proper sorting, because it would be alot of trouble to check each time and probably lag the system because of the processing needed. And yes often times I answer my own questions by finding examples of what I need or that I can adapt my problem into, Once I do something I can always do It, I just need it seen done once in order for me to catch on. Hence the reason I love this forum. Thanks much for your help as I now think that I should be able to finish out all of this on my own as long as it now lists the vial #'s in the correct order heh, Once again, Thanks.
|
|
|
|
 |
Davos Adept
Joined: 30 Jan 2003 Posts: 228 Location: USA
|
Posted: Sat Oct 11, 2003 8:11 am |
Ok i did this
#loop 60,0 {#IF (%db( @Vials, %i)) {#FORALL %db( @Vials, %i) {put %i in pack}}}
which should be all thats needed to happen, exept its triggering some kind of trigger loop for some reason, the scroll is SOO bad and SOO long that I cant even really decifer what its doing, its definatly not putting them in correctly tho...any ideas? |
|
|
|
 |
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Oct 11, 2003 5:14 pm |
This might not be the most efficient, but I think it works. It didn't give any error messages in offline testing. Feel free to change setting names, I just didn't want it to get mixed up with the script you and Vij have been working on. I based it on the work you two have already done.
#AL LBsort {#VAR LB1 "";#T- VialsLB|LB2 trigger;#T+ VialsLB;elixlist}
#CLASS VialsLB disable
#TR { vial(%d)%s*%s(%d)%s%d$} {#T+ LB2;#ADDK LB1 %1 %2}
#TR LB2 {%dh,%s%dm%s} {#T- LB2;#T- VialsLB;#LOOP 60,0 {#LOOPDB @LB1 {#IF (%val = %i) {Put %key in pack}}}}
#CLASS 0
#T- VialsLB |
|
|
|
 |
Davos Adept
Joined: 30 Jan 2003 Posts: 228 Location: USA
|
Posted: Sat Oct 11, 2003 7:46 pm |
hah that worked perfectly, 150 posts later and Lightbulb fixes it, thanks a bunch.
|
|
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Sun Oct 12, 2003 3:05 am |
I could have been nice and told you that "put %i in pack" should be "put %j in pack", but I figured you would find it. Guess Lightbulb was sick of seeing this thread go on.
|
|
|
|
 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|