Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Thu May 25, 2006 9:13 am   

extracting from string
 
I am trying to populate an array with a list of posible attack targets.

Currently i am using something like this.

#VAR testline {%line}
killtest=%replace( @testline, ", ", "|")
killtest=%replace( @killtest, " and ", "|")
killtest=%replace( @killtest, " is standing here.", "")
killtest=%replace( @killtest, "s are standing here.", "")
killtest=%replace( @killtest, " are standing here.", "")
ect
ect
ect
stufftokillhere=""
#FORALL @killtest {#VAR stufftokillhere {%additem( %word( %i, %numwords( %i)), @stufftokillhere)}}
#ECHO {@stufftokillhere}

Now this seems like alot of overhead to do what i want.

Is there a way to parse %line for all instances of members of an array @stufftokill and populate @stufftokillhere without so many recursive %replace commands?
_________________
Discord: Shalimarwildcat
Reply with quote
Arcane_of_Discworld
Wanderer


Joined: 29 Jan 2002
Posts: 99
Location: UK

PostPosted: Thu May 25, 2006 10:04 am   
 
I would also like to know if there is a more efficient method of doing this as I have a similar setup. One suggestion I can make is that you can nest %replace() functions such as:

killtest=%replace(%replace(%replace(%replace(%replace( @testline, ", ", "|") ," and ", "|") ," is standing here.", ""), "s are standing here.", "") ," are standing here.", "")
Reply with quote
Larkin
Wizard


Joined: 25 Mar 2003
Posts: 1113
Location: USA

PostPosted: Thu May 25, 2006 1:01 pm   
 
You could experiment with %subregex and combine your patterns together. You'd use two calls to %subregex to accomplish the above: one for replacing commas and 'and' with |, and one for replacing other extraneous text with an empty string.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Sat Nov 04, 2006 6:10 pm   Counting odd things
 
Quote:
Three horses, a yellow chicken, two dogs and a cat are here.


I want a means to reliably count the number of mobs on a line similar to the above one and store it in a variable.

totalmobs=7
_________________
Discord: Shalimarwildcat
Reply with quote
Ceres
Wanderer


Joined: 25 May 2006
Posts: 88

PostPosted: Sat Nov 04, 2006 11:15 pm   
 
This code is specific to discworld Mud, and no I won't be providing support for it if you cannot get it to work.
Code:
#CLASS {Misc|RoomContents|InitialContents} {enable}
#ALIAS InitialRoomContentsAlias {#PRIORITY {#VARIABLE RoomContentsList {}}
 #PRIORITY {#VARIABLE ContentsNumberReplace {}}
 #PRIORITY {#VARIABLE ParsedPluralRoomContents {}}
 #PRIORITY {#VARIABLE PlayersInRoom {0}}
 #PRIORITY {#IF (%pos( "wisps", @RawRoomContents)) {:1:#SAY %ansi( bold, red)Talker mistrigger!
   #VARIABLE RawRoomContents {}} {#NOOP}}
 #PRIORITY {#VARIABLE RawRoomContents {%push( "control", @RawRoomContents)}}
 #PRIORITY {#VARIABLE RawRoomContents {%additem( "control", @RawRoomContents)}}
 #PRIORITY {#FORALL @EndingsOfRoomLiving {#VARIABLE RawRoomContents {%replace( %lower( @RawRoomContents), %lower( %i), "")}}}
 #PRIORITY {#VARIABLE ParsedRoomContents {%replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( @RawRoomContents, ", ", "|"), " and ", "|"), " (hiding)", ""), " who ", "|"), "k|h", "k and h"), "y|w", "y and w"), "|a ", "|the "), "|an ", "|the "), " is ", ""), " are ", ""), "  ", " lounging "), "k|w", "k and w")}}
 #PRIORITY {#FORALL @InvisibleLiving {#DELITEM ParsedRoomContents {%lower( %i)}}}
 #PRIORITY {#VARIABLE SingularRoomContents { %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( @ParsedRoomContents, "s|", "|"), "rie|", "ry|"), "lve|", "lf|"), "sse|", "ss|"), "die|", "dy|"), "dren|", "d|"), "es|", "ess|"), "ni|", "nis|"), "go|", "gos|"), "las|", "lass|"), "dut|", "duts|")}}
 #PRIORITY {#DELITEM SingularRoomContents control}
 #PRIORITY {#FORALL @SingularRoomContents {#VARIABLE TempRoomContents {%i}
   #IF (%word( @TempRoomContents, 1, " ")!="the" and %ismember( %word( @TempRoomContents, 1, " "), @ContentsCounter)) {#VARIABLE ContentsNumberReplace %additem( %word( @TempRoomContents, 1, " "), @ContentsNumberReplace)} {}
   #IF (%ismember( %word( @TempRoomContents, 1, " "), @ContentsCounter)) {#LOOP %ismember( %word( @TempRoomContents, 1, " "), @ContentsCounter) {#VARIABLE RoomContentsList %additem( @TempRoomContents, @RoomContentsList)}} {#ADDITEM RoomContentsList {@TempRoomContents}}}}
 #PRIORITY {#VARIABLE RoomContentsList {%push( "control", @RoomContentsList)}}
 #PRIORITY {#FORALL @ContentsNumberReplace {#VARIABLE RoomContentsList {%replace( @RoomContentsList, |%i, "|the")}}}
 #PRIORITY {#DELITEM RoomContentsList control}
 #PRIORITY {#FORALL @ContentsNumberReplace {#VARIABLE ParsedPluralRoomContents {%replace( @ParsedRoomContents, |%i, "|one of the")}}}
 #PRIORITY {#FORALL @RoomContentsList {#ADDITEM ParsedPluralRoomContents {%i}}}
 #PRIORITY {#DELITEM ParsedPluralRoomContents control}
 #PRIORITY {#VARIABLE PluralRoomContents {@ParsedPluralRoomContents}}
 #PRIORITY {#IF (%ismember( 1, @RoomContentsList)) {:1:#SAY Debug on ~@RoomContentsList activated, RoomContentsList is @RoomContentsList
   #DELITEM RoomContentsList 1}}
 #PRIORITY {#FORALL {@RoomContentsList} {#IF (%ismember( %word( %i, 1, " "), %lower( @OnlinePlayers))!=0) {#ADD PlayersInRoom 1}}}
 #PRIORITY {:Commands:#SAY %time( hh:mm:ss:zzz) %ansi( bold, red)Contents processed}}
#VARIABLE InitContentsTrigger {0}
#TRIGGER { {@EndingsOfRoomLiving}.$} {#IF (@InitContentsTrigger) {RewriteInitialContentsTriggers}
 #ADD InitContentsTrigger 1}
#CONDITION {\b(?:@OnlinePlayers)\b} {#CW blueviolet,black} {reparse|regex}
#CONDITION {\b(?:@CreList)\b} {#CW red,black} {reparse|regex}
#REGEX {^(?RawRoomContents:.+) (?:is|are) (?:@EndingsOfRoomLiving)\.$} {#PRIORITY {#VARIABLE InitContentsTrigger {0}}
 #PRIORITY {:Commands:#SAY %time( hh:mm:ss:zzz) %ansi( bold, red)Contents detected.}
 #PRIORITY {#COLOR 11}
 #PRIORITY {InitialRoomContentsAlias}}
#CLASS 0
#CLASS {Misc|RoomContents|InitialContents|InitialContentsVariables}
#VARIABLE EndingsOfRoomLiving {seated in a luxurious armchair|sitting on a hard wooden stool|scuttling around|standing here|skulking in the shadows|busy getting dirty|buzzing around|trying to avoid touching the ground|sprawled lazily on the ground|sitting here|slithering about|on guard|sitting at the wobbly table| the giant fruitbat flying|dozing under a bush|lying sprawled on his side|lying sprawled on her side|sniffing at a tree trunk|lying here|rooted to the ground here|crouching here|perched on a branch|lying half-concealed in the bushes|sniffing into the undergrowth|nosing through the leaf litter|standing around|looking a bit lost|squatting on the ground|rootling about the ground|hovering several feet up|lurking in the brush|not doing very much at all|looking bored|staring into space|flittering about|zipping about|looking for something to eat|fiddling with a piece of armour|perched on the street lamp|loitering|hovering|wearing a sandwich board|swatting away dust|curled up into a ball|prowling|lounging|keeping an eye out|lying on his side|stretched out on the ground|dozing in the grass|flopped on the ground|lying on her side|sitting very straight|draped on the ground|grazing|spread out on the ground|towering modestly|lying in the dust|towering significantly|floating here|darting about|clinging to a precarious twig|flying a bit above the ground|perched nearby|looking hungry|hopping along the ground|perching on a tree branch|wasting time|hanging overhead|looking for insects|hanging upside down|looking for gossip|trying to look busy|preening|ambling about|darting around|admiring her curls|looking wise|complaining|telling tall tales|picking crumbs on the floor|sprawled near the fire|standing beside the fire|fiddling with a piece of armour|lounging amiably on the wobbly table|hopping around|pecking at the ground|floating in the air here|flying above the ground here|sitting on some flat rocks|flying|flapping sadly close to the ground here|wearing a sandwich board|basking in the sun|lying on the bar|purring softly|looking for insects|running around|chewing cud|scurrying about|doing nothing|wasting time|preening|looking philosophical|telling bad goat jokes|looking for gossip|scuttling about|looking to swap news|lurking about|pecking at something|lazing about doing nothing|sitting at the bar|kneeling submissively|lying on the wobbly table|standing on the remains of a table|meditating here|sitting on the wobbly table}
#VARIABLE ContentsNumberReplace {four|three|two}
#VARIABLE RawRoomContents {control|four orange canaries are , three pink elephants are and two fluffy pineapples|control}
#VARIABLE ParsedRoomContents {control|four orange canaries|three pink elephants|two fluffy pineapples|control}
#VARIABLE SingularRoomContents {four orange canary|three pink elephant|two fluffy pineapple}
#VARIABLE TempRoomContents {two fluffy pineapple}
#VARIABLE ParsedPluralRoomContents {four orange canaries|three pink elephants|one of the fluffy pineapples|the orange canary|the pink elephant|the fluffy pineapple}
#VARIABLE ContentsCounter {the|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen}
#CLASS 0

To get a count from the above code add the following to the end of the InitialRoomContentsAlias:
Code:
#VARIABLE MobCount {%numitems(@RoomContentsList)}
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4691
Location: Pensacola, FL, USA

PostPosted: Sun Nov 05, 2006 6:04 pm   
 
That works great, thanks.
_________________
Discord: Shalimarwildcat
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net