|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Wed Nov 19, 2003 2:49 am
Lightbulb container |
Lightbulb, think you can help me modify your script to work with my mud. My mud puts the contents all on the next line following "It contains:" until it sees a "."
A cupboard made of simply but elegantly carved rosewood with silver hinges.
It contains:
5 pounds of roast parrot meat, 373 pounds of roast wyvern meat, 21 pounds of roast beef, 120 pinches of elvish pipeweed, 32 square feet of poor balsa board, 70 ounces of pine shavings, 68 square feet of ostrich hide, 5 copper tankards, 4 chunks of coal, 30 pinches of dried tobacco, 5 balsa skewers, 8 leaves of logacha, a balsa spoon, 3 ingots of copper, 5 copper goblets, 4706 ounces of alum, 225 pounds of roast venison, 9 pounds of roast snake meat, 2400 square feet of balsa board, 6 boiled eggs, 95 pounds of roast leopard meat, 78 pounds of roast pork, 243 chunks of kalunite.
>
I'm not very good at multi-line triggers.
I tried using
#tr {It contains~:$(*).} {#GAG;#VAR contents {%1};#VAR contents %replace( {@contents}, ", and ", "|");#VAR contents %replace( {@contents}, ", ", "|");#VAR contents %countlist( @contents);ContentsSummary}
but that does not seem to work. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Wed Nov 19, 2003 2:54 am |
#TR {It contains~:} {#GAG}
#COND {(*).} {#GAG;#VAR contents {%1};#VAR contents %replace( {@contents}, ", and ", "|");#VAR contents %replace( {@contents}, ", ", "|");#VAR contents %countlist( @contents);ContentsSummary} (within|param=1} |
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Wed Nov 19, 2003 3:00 am |
Thanks shalimar, its working using the multi-state trigger!
|
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Wed Nov 19, 2003 3:21 am |
hmm.
ok I want to refine this a bit more.
Right now I get the following:
The container has:
1 18 copper farthings
1 8 boiled eggs
> 1 a mortar and pestle
1 4 small metal vials containing some white mist
1 4 swordfish steaks
1 an extremely small myrtle lute
If the items are already stacked, I want to move the number in the front of the item, into the quanitity field. So instead of seeing "1 18 copper farthings" I would see "18 copper farthings". I only want to do this if the item has a number at the front.
Secondly, I want to strip out the word "an" or "a" if its the first word in the list.
So my final list should look like:
The container has:
18 copper farthings
8 boiled eggs
1 mortar and pestle
4 small metal vials containing some white mist
4 swordfish steaks
1 extremely small myrtle lute
Here is the script I am using right now.
#CLASS {container} {setdef}
#ALIAS ContentsSummary {#SAY The container has~:;#LOOPDB @contents {#SAY %val %key}}
#TRIGGER {It contains~:} {#GAG}
#COND {(*).$} {#GAG;#VAR contents {%1};#VAR contents %replace( {@contents}, ", and ", "|");#VAR contents %replace( {@contents}, ", ", "|");#VAR contents %countlist( @contents);#LOOPDB @contents {#SAY %val %key};ContentsSummary}
#CLASS 0 |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Nov 19, 2003 5:19 am |
It appears that your MUD already does the counting for you, so you can skip the %countlist. Just use #FORALL to loop through your list and display each item. Removing a/an (or converting them to 1) can be handled with %replace, either before or after converting the string to a list, or can be done during the display phase.
#FORALL @contents {#IF (%word( %i, 1) = "a") {#SAY 1 %right( %i, 2)} {#IF (%word( %i, 1) = "an") {#SAY 1 %right( %i, 3)} {#SAY %i}}} |
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Wed Nov 19, 2003 4:09 pm |
Actually I still want to do the counting. My mud stacks and counts MOST things, but occassionally some items will not get stacked and counted. Things like food is always stacked, but items like weapons are not stacked.
I'll take a look at your suggestions tonight. That should help me resolve the ones that do get stacked.
Thanks! |
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Thu Nov 20, 2003 3:04 am |
this is a pain. I'm trying to move the number, if its the first word, out to the second field in the data record, otherwise move 1. Then I am trying to loop through and replace all the "an" or "a".
The code below is not working at all? Anybody got some time to help me chew through it.
#GAG
#VAR contents {%1}
#VAR contents %replace( {@contents}, ", and ", "|")
#VAR contents %replace( {@contents}, ", ", "|")
#VAR contents %countlist( @contents)
#FORALL @contents {#IF (%word( %i, 1) = "a") {#VAR contents3 %addItem( %right( %i, 3), contents3)} {#VAR contents3 %addItem( %i, contents3)}}
;
#FORALL @contents3 {#IF (%word( %i, 1) = "a") {#VAR contents2 %addItem( %right( %i, 2), contents2)} {#IF (%word( %i, 1) = "an") {#VAR contents2 %addItem( %right( %i, 3), contents2)} {#VAR contents2 %addItem( %i, contents2)}}}
;#LOOPDB @contents {#SAY %val %key}
ContentsSummary |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Thu Nov 20, 2003 5:06 am |
"My mud stacks and counts MOST things, but occassionally some items will not get stacked and counted. Things like food is always stacked, but items like weapons are not stacked."
Please provide an example.
For the current example (in the original post), this script will work:
#CLASS container setdef
#TR {^It contains:} {#GAG}
#COND {(*).$} {#GAG;#VAR contents {%1};#VAR contents %replace( {@contents}, ", ", "|");ContentsSummary}
#AL ContentsSummary {#FORALL @contents {#IF (%word( %i, 1) = "a") {#SAY 1 %right( %i, 2)} {#IF (%word( %i, 1) = "an") {#SAY 1 %right( %i, 3)} {#SAY %i}}}}
#CLASS 0
It's not surprising that your script isn't working at all. You used %countlist to convert @contents from a LIST to a RECORD, then tried to use it with #FORALL which requires it to still be a LIST.
#FORALL works on LIST-variables. It doesn't work on RECORD-variables.
#LOOPDB works on RECORD-variables. It doesn't work on LIST-variables.
%countlist( list) requires a LIST as its parameter, but it returns a RECORD.
%additem( s, list) requires a LIST as its second parameter. contents3 is not a list (unless you want "contents3" as the only item). @contents3 is a list (if it's a list-variable). (When to use varname and when to use @varname can get very frustrating at times ) |
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Fri Nov 21, 2003 1:05 am |
ok, here is a better example from my mud
A somewhat large piece of fine furniture designed to store a person's clothing and equipment. It is made of rosewood with silver hardware. There is a silver nameplate on the door. The name "Talahaski" is inscribed on the nameplate.
It contains:
300 ounces of alum, a leather bracer, a leather bracer, 12 square feet of lynx pelt, a silver mirror, a silver mirror, a silver mirror, a silver mirror, a silver mirror, a silver mirror, a silver mirror, a silver mirror, a silver mirror, a silver mirror, a somewhat small balsa target shield, a conch shell, a tiger maple target shield, a perfume jar, a burgundy crystal goblet, a perfume jar, a perfume jar of aromatic oil, and A delicate web of crystal.
You will notice the mud counts some items but not all. The mirrors, bracers, perfume jar are NOT counted.
Currently I see the following with the triggers I have - which are not working.
The container has:
1 contents2|300 ounces of alum
2 a leather bracer
1 12 square feet of lynx pelt
10 a silver mirror
1 a somewhat small balsa target shield
1 a conch shell
1 a tiger maple target shield
2 a perfume jar
1 a burgundy crystal goblet
1 a perfume jar of aromatic oil
1 A delicate web of crystal
I would like to see:
The container has:
300 ounces of alum
2 leather bracer
12 square feet of lynx pelt
10 silver mirror
1 somewhat small balsa target shield
1 conch shell
1 tiger maple target shield
2 perfume jar
1 burgundy crystal goblet
1 perfume jar of aromatic oil
1 delicate web of crystal
Hmm, the formatting did not come over on the forum correctly. I want the above list to line up with the count on the left and a column of items on the right |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Fri Nov 21, 2003 8:02 pm |
You have two types of items.
1. Grouped items which have already been counted. These all have a number as the first word of the item.Since they've already been counted, you should NOT use %countlist on them.
2. Single items which haven't been counted. These don't have a number as the first word but may have "a" "an" or "A". Since they haven't been counted, you should use %countlist on them.
Since the two types are mixed together, the obvious first step after creating the list is to separate them (I think you attempted to do this). After they are separated, use the appropriate method to display each type.
#TR {It contains:} {#GAG}
#COND {(*).} {
#GAG
#VAR contents {%1}
#VAR contents {%replace( {@contents}, ", and ", "|")}
#VAR contents {%replace( {@contents}, ", ", "|")}
#VAR contents2 {}
#VAR contents3 {}
#VAR contents4 {}
#FORALL @contents {
#IF (%isnumber( %word( %i, 1))) {
#ADDI contents2 {%i}
} {
#VAR contents3 {%i}
#IF (%word( %i, 1) = "a") {#VAR contents3 {%right( %i, 2)}}
#IF (%word( %i, 1) = "A") {#VAR contents3 {%right( %i, 2)}}
#IF (%word( %i, 1) = "an") {#VAR contents3 {%right( %i, 3)}}
#IF (%word( %i, 1) = "An") {#VAR contents3 {%right( %i, 3)}}
#VAR contents4 {%additem( @contents3, @contents4)}
}
}
#VAR contents5 {%countlist( @contents4)}
#FORALL @contents2 {#SAY %i}
#LOOPDB @contents5 {#SAY %val %key}
}
As for formatting, you'll have to do that yourself. I've spent enough time on this already. |
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Fri Nov 21, 2003 9:29 pm |
Thanks for all the help. I think I was struggling with the DB parts since I have not worked with DB functions before. I was getting confused with what objects were a data record and which were string list. I'm used to using string list only for most of my triggers. One of these days I should go back and rewrite a lot of them to use the data records.
I'll test that code out tonight.
Again, I appreciate your help. Sorry if I took up too much of your time.
Oh, If you don't mind I would like to post the final code on my muds site for others to use.
I still have a few tweaks I want to add which I'll play with tonight. The formatting should not be too hard. I also want to have it sort by the number of items. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Sat Nov 22, 2003 4:32 am |
Make sure it works in actual practice before posting it, please. As for the time, that's mostly a result of the complexity of the problem. I'm just not willing to spend more time adding an additional layer of complexity to line things up.
|
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Mon Nov 24, 2003 3:34 am |
is there a way to do this so that the count is at the end, or not shown at all if only one item?
longsword (x3)
platemail
sharp dagger (x2)
healing potion
ect |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Nov 24, 2003 6:17 pm |
Not easily. It's possible, but I'm not going to do it.
|
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Sun Nov 30, 2003 6:39 am |
In case anybody else was following this thread, I figure I'll post the changes to the script so far.
This version now has formatting along with placing the entire list in a single DB Variable instead of a DB Variable and a stringlist variable.
#TR {It contains:} {#GAG}
#COND {(*).} {
#GAG
#VARIABLE contents {%1} {} Container
#VARIABLE contents {%replace( @Container/contents, ", ", "|")} {} Container
#VARIABLE contents2 {} {} Container
#VARIABLE contents3 {} {} Container
#VARIABLE contents4 {} {} Container
#FORALL @Container/contents {#IF (%isnumber( %word( %i, 1))) {#ADDITEM contents2 {%i}} {
#VARIABLE contents3 {%i} {} Container
#IF (%word( %i, 1) = "a") {#VARIABLE contents3 {%right( %i, 2)} {} Container}
#IF (%word( %i, 1) = "A") {#VARIABLE contents3 {%right( %i, 2)} {} Container}
#IF (%word( %i, 1) = "an") {#VARIABLE contents3 {%right( %i, 3)} {} Container}
#IF (%word( %i, 1) = "An") {#VARIABLE contents3 {%right( %i, 3)} {} Container}
#VARIABLE contents4 {%additem( @Container/contents3, @Container/contents4)} {} Container
}}
#VARIABLE contents5 {%countlist( @contents4)} {} Container
#FORALL @Container/contents2 {
#VARIABLE ContentsCount {%word( %i, 1)} {} Container
#VARIABLE Container/Contentskey {%right( %remove( @Container/ContentsCount, %i), 1)} {} Container
#ADDKEY contents5 {@Container/Contentskey} {@Container/ContentsCount}
}
#LOOPDB @Container/contents5 {#SAY %format( "&5.0f &s &s", %val, " ", %key)}}
I'm still working on trying to figure out how to sort the final contents5 DB Variable by the number of items.
Again, many thanks to the help Lightbulb has provided. |
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Fri Dec 12, 2003 6:56 am |
Ok, I've made a number of changes here again.
Again just posting an updated version in case anybody is interested. Feel free to point out more efficient ways of doing this.
In this version I moved away from variables and used the database. I created a database with fields of object and count. I then created a view called CoByCount with shows all records but is sorted by the count field. This allows me to sort the list.
By the way, anybody know of a way to load the DB module of zmud if the user has not hit the DB window yet. I could not find a way to automatically open the window in the background. I hoped #DBLOAD would do that, but it does not seem to.
#TR {It contains:} {#GAG}
#COND {(*).} {
#DBLOAD co
#GAG 0
#DBFIRST
#WHILE (!%null( %rec)) {#DBDELETE &Num}
#SHOW -------------------------------------------------------------------------------
#VARIABLE Contents {%1} {_nodef} Container
#VARIABLE Contents {%replace( @Container/Contents, ", ", "|")} {} Container
#VARIABLE Hold_Contents {} {_nodef} Container
#FORALL @Container/Contents {
#VARIABLE Hold_Contents {%i} {_nodef} Container
#IF (%word( @Hold_Contents, 1) = "a") {#VARIABLE Hold_Contents {%right( @Hold_Contents, 2)} {_nodef} Container}
#IF (%word( @Hold_Contents, 1) = "A") {#VARIABLE Hold_Contents {%right( @Hold_Contents, 2)} {_nodef} Container}
#IF (%word( @Hold_Contents, 1) = "an") {#VARIABLE Hold_Contents {%right( @Hold_Contents, 3)} {_nodef} Container}
#IF (%word( @Hold_Contents, 1) = "An") {#VARIABLE Hold_Contents {%right( @Hold_Contents, 3)} {_nodef} Container}
#IF (%isnumber( %word( @Hold_Contents, 1))) {
#NEW cobycount object=%right( %replace( @Hold_Contents, %word( @Hold_Contents, 1), ''), 1) count=%word( @Hold_Contents, 1)} {
#IF (%query( &Object = @Hold_Contents)) {
#DBGET %query( &Object = @Hold_Contents)
&Count=%eval( &Count+1)
} {
#NEW cobycount object=@Hold_Contents count=1}
}
}
#VIEW cobycount
#DBFIRST
#WHILE (!%null( %rec)) {
#SHOW %format( "&5.0f &s &s", &count, " ", &object)
#DBNEXT
}
#SHOW -------------------------------------------------------------------------------} |
|
|
|
barst Newbie
Joined: 06 Apr 2003 Posts: 1 Location: Germany
|
Posted: Fri Dec 12, 2003 8:36 am |
Hi Talahaski,
maybe you could give me more detailed instructions on how to set it up
to work with dartmud.
thanks |
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
Posted: Fri Dec 12, 2003 6:00 pm |
I plan to post it on the dartwiki site with full instructions at some point. Otherwise you can email me. Talahask@optonline.net
|
|
|
|
Talahaski Enchanter
Joined: 10 Oct 2000 Posts: 656 Location: USA
|
|
|
|
|
|
|
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
|
|