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
Rtoo
Beginner


Joined: 30 Jul 2009
Posts: 11

PostPosted: Thu Jul 30, 2009 7:04 pm   

Captured Varible with Multiple words, expanding them separately
 
I am trying to get text I captured into a varible that has mulitiple words to expand into seperate words.

Example: @mobname = A grey fox

I want to make an alias that will do:

where A
where grey
where fox

Ultimately it would not do a where for a, the, etc. I can live with that if I can get the rest to work though.
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Thu Jul 30, 2009 8:04 pm   
 
You want to take a look at %replace, #forall and #if because you need to replace the spaces in the string with bars which allows you to loop through each item with #forall and while you have each item do a check with #if and ignore it if it's an A or the. You might want to do a %lower to the string first of all as that makes it easier doing the word checking with #if.

EDIT: Oh and you could keep the unwanted words in a string list variable and use a %ismember to do the unwanted word checking in one #if statement.
_________________
Taz :)
Reply with quote
shalimar
GURU


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

PostPosted: Thu Jul 30, 2009 11:46 pm   
 
#FORALL "a|an|the|etc" {mobname=%trim(%replace(%lower(@mobname), %i))}
#LOOP %numwords(@mobname) {where %word(@mobname, %i)}
_________________
Discord: Shalimarwildcat
Reply with quote
Rtoo
Beginner


Joined: 30 Jul 2009
Posts: 11

PostPosted: Fri Jul 31, 2009 4:01 pm   
 
This works pretty well, but if the mob name has an a|an|the, etc in it, it is being stripped also.

So the reaper is coming out as...

where reper

Thanks though, still much better than I had!
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Jul 31, 2009 5:00 pm   
 
Try this

#FORALL "a|an|the|etc" {mobname=%trim(%subregex(%lower(@mobname), %concat("\b",%i,"\b")))}
_________________
Asati di tempari!
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Jul 31, 2009 11:24 pm   
 
It might be simpler just to do:

mobname=%trim(%subregex(%lower(@mobname),"\b(a|an|the|whatever)\b"))

which avoids the loop and multiple regex compiles.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Mon Aug 03, 2009 4:27 pm   
 
You'd have to loop somewhere though otherwise you'd have just grey fox rather than grey and then fox.
_________________
Taz :)
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