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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sat Apr 12, 2008 6:57 pm   

Splitting a Variable?
 
#regex grab_helm_cur {^You wear [a|the|some] (\w+) (\w+) .* (\w+) on your \w+.$} {cur_helm=%1+" "+%2+" "+%3} {General Triggers|EQ}

#regex grab_helm_last {^You stop using [a|the|some] (\w+) (\w+) .*\.$} {last_helm=%1+" "+%2+" "+%3} {General Triggers|EQ}

Are two example triggers, I'll be having them for each piece of equipment. The major problem comes in getting it to work in auto_equipping.

I grab 3 slices of the name so that I can have 3 words, one of which is hopefully a keyword. What I'm wondering is: How can I make it so that when I use a trigger to equip, it takes the variable, splits all of the words into separate strings and then goes through a loop, trying to use them until one is successful.

If I can use this dynamically, then I can take a whole string of the item:

You wear a bull leather helmet on your head.

No matter what it is, say it's:

You stop using a fiery helmet of bull leather.

and then compare each word until one works and I get the string:

You wear a fiery helmet of bull leather on your head.

Then it would abort and be fine.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sat Apr 12, 2008 7:18 pm   
 
OK, you are looking for the %word and %numwords function for splitting the variable into separate words. #loop %numwords(%1) {wear %word(%1,%i)}

You have an error in your trigger though.

[a|the|some] should be (?:a|the|some)

The way you have it will match any one of the characters within the [] aehmost or a |.
When I know you want to match one of the words "a the or some".
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sat Apr 12, 2008 7:39 pm   
 
Is i the default loop variable? I know in many programming languages i is used, but I forget whether or not you have to set it up. Also, I can set up an expression for it, right? So that it can abort if the equipping is successful?
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Sat Apr 12, 2008 7:50 pm   
 
%i is indeed the default loop variable.

I just gave a quick and dirty example, you would probably want to use an Alarm and loop through it manually, again like I showed oldguy yesterday for his delayed commands using Oninput.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Sat Apr 12, 2008 8:44 pm   
 
Well, looping through it manually would almost defeat the purpose of it. I'll play around with it, but it should be easy to catch the phrase that it's equipped and abort is somehow.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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