|
hannerii Newbie
Joined: 14 Mar 2007 Posts: 7
|
Posted: Thu Apr 15, 2010 12:49 pm
Parsing CSV to a list variable |
Hello everyone, I have been trying to parse a variable length CSV output into a list and as of yet have had no luck. Although I am using this in DragonRealms (Simutronics) i think this would be a universal issue. When I type the health command i get:
Code: |
Your body feels at full strength.
Your spirit feels full of life.
You have a bruised head, a few nearly invisible scars along the head, some minor abrasions to the neck, a few nearly invisible scars along the neck, severe scarring along the right arm, minor swelling and bruising around the left arm, an occasional twitching in the left arm, minor swelling and bruising around the right leg, an occasional twitching in the right leg, an occasional twitching in the left leg, some minor abrasions to the left hand, a few nearly invisible scars along the left hand, cuts and bruises about the chest area, a constant twitching in the chest area, minor scarring along the abdomen, some tiny scratches to the back, a few nearly invisible scars along the back, some minor swelling and bruising around the right eye, a few nearly invisible scars along the right eye, some minor abrasions to the left eye, a few nearly invisible scars along the left eye, slight numbness in your arms and legs. |
What I'm wanting to do is take the "You have ..." and put all that CSV information into a list that i can run through and perform a healing script. Any assistance would be greatly appreciated. |
|
|
|
Martaigne Wanderer
Joined: 05 Jan 2002 Posts: 88 Location: Atlanta, GA
|
Posted: Thu Apr 15, 2010 4:24 pm |
#TRIGGER {^You have (*).$} {HealthStringList = %replace(%-1,", ", "|")}
You may wish to use this in a conditional trigger in order to avoid any other random lines matching this trigger from firing. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu Apr 15, 2010 5:17 pm |
That's going to cause problems when the upper-level wound/scar messages come. For some stupid reason, Simutronics (at least in dragonrealms) decided to use commas in the elements of this particular comma-delimited list.
You would be better off using a #forall to loop through body parts, replacing them with the same plus the | for stringlists. After that, you can then look for beginning-of-element phrases that are then anchored with the |. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Martaigne Wanderer
Joined: 05 Jan 2002 Posts: 88 Location: Atlanta, GA
|
Posted: Thu Apr 15, 2010 7:51 pm |
Ah, I didn't know that Simutronics did something dumb like that. I shouldn't be surprised, considering.
|
|
|
|
hannerii Newbie
Joined: 14 Mar 2007 Posts: 7
|
Posted: Thu Apr 15, 2010 10:42 pm |
So would I want a seperate string list with the different wounds that include commas then do a comparison or something? I try not to be surprised with Simutronics. Hell I can't even get a response from their customer server/tech support people through email. Apparently they changed Empath spells and replaced four spells with two others, only trouble is my character still knows two of the old spells.
|
|
|
|
Private Adept
Joined: 10 Jan 2002 Posts: 264 Location: USA
|
Posted: Sat Apr 17, 2010 7:31 pm |
Code: |
<class name="test" id="456">
<var name="bparts" type="StringList" id="8425">eye|head|neck|arm|leg|hand|legs|area|back</var>
<trigger priority="84260" id="8426">
<pattern>^You have (*) ({@bparts}).</pattern>
<value>#GAG
bodyparts = %concat(%1, %char(32), %2)
#FORALL @bparts {bodyparts = %replace(@bodyparts,%i%char(44)%char(32), %i%char(124))}
#FORALL @bodyparts {#SHOW {Wounds: %i}}</value>
</trigger>
<var name="bodyparts" id="8427">a few nearly invisible scars along the head|some minor abrasions to the neck|a few nearly invisible scars along the neck|severe scarring along the right arm|minor swelling and bruising around the left arm|an occasional twitching in the left arm|minor swelling and bruising around the right leg|an occasional twitching in the right leg</var>
<alias name="testbparts" id="8428">
<value>$testbparts = %null
#LOOP %random(2,10) {$testbparts = %concat($testbparts, @testparts.%i, %char(44), %char(32))}
#SHOW {}
#SHOW %replace(%concat("You have ", $testbparts, "."),%char(44)%char(32)%char(46),%char(46))
#SHOW {}
</value>
</alias>
<var name="testparts" type="StringList" id="8430">a few nearly invisible scars along the head|some minor abrasions to the neck|a few nearly invisible scars along the neck|severe scarring along the right arm|minor swelling and bruising around the left arm|an occasional twitching in the left arm|minor swelling and bruising around the right leg|an occasional twitching in the right leg|an occasional twitching in the left leg|some minor abrasions to the left hand|a few nearly invisible scars along the left hand|cuts and bruises about the chest area|a constant twitching in the chest area|minor scarring along the abdomen, some tiny scratches to the back|a few nearly invisible scars along the back|some minor swelling and bruising around the right eye|a few nearly invisible scars along the right eye|some minor abrasions to the left eye|a few nearly invisible scars along the left eye|slight numbness in your arms and legs</var>
</class>
|
>testbparts
Wounds: a few nearly invisible scars along the head
Wounds: some minor abrasions to the neck
>testbparts
Wounds: a few nearly invisible scars along the head
Wounds: some minor abrasions to the neck
Wounds: a few nearly invisible scars along the neck
Wounds: severe scarring along the right arm
Wounds: minor swelling and bruising around the left arm
Wounds: an occasional twitching in the left arm
Wounds: minor swelling and bruising around the right leg
Wounds: an occasional twitching in the right leg
>testbparts
Wounds: a few nearly invisible scars along the head
Wounds: some minor abrasions to the neck
Wounds: a few nearly invisible scars along the neck
Wounds: severe scarring along the right arm
this script might need tuning on your mud, i hadda add the test at end for a bodypart word, else it matched other spells :P
just create a new class and paste the code in to test it, the class's name is test in my root package
Is this what you needed?
i sdded another trigger onto what i did above....
Code: |
<trigger priority="84330" id="8433">
<pattern>^Wounds: (*) {along|to|around|in|about|} {your|the} (*)$</pattern>
<value>#LOOPDB @woundtypes {#IF (%1 = %key) {
#GAG
#SHOW {%ansi( reset)Wound: %ansi( yellow)%format( "&-10s", %2)%char( 32)%ansi( reset)Part: %eval(%val)}
}}</value>
</trigger>
<var name="woundtypes" type="Record" id="8434">minor scarring=%ansi(green)minor|severe scarring=%ansi(high,red)severe|a few nearly invisible scars=%ansi(yellow)light|cuts and bruises=%ansi(high,red)serious|some minor abrasions=%ansi(green)minor|an occasional twitching=%ansi(green)minor|a constant twitching=%ansi(high,red)serious|some tiny scratches to the back=%ansi(yellow)light|some minor swelling and bruising=%ansi(green)minor|slight numbness=%ansi(yellow)light|minor swelling and bruising=%ansi(green)minor</var>
|
dunno how severe all the wound are... but it outputs:
Wound: neck Part: minor
Wound: neck Part: light
Wound: right arm Part: severe
but formatted like:
Code: |
Wound: neck Part: minor
Wound: neck Part: light
Wound: right arm Part: severe
|
|
|
|
|
|
|
|
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
|
|