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
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Sun Feb 07, 2016 8:48 am   

Help matching a string
 
When I walk into a room, I see

(mob)A monsters name <and possibly a bunch of random other stuff, wounded, hit points, etc>

The (mob) is always constant no matter what.
A monsters name is stored in a list

What I want to do, is compare the list of items, to the partially matched line after (mob)... If it matches, I want it to output the matched name. So for example:

(mob)A mangy dog.
(mob)A feral cat [wounded] [89%].
(mob)A timid mouse (demoralized).
(mob)A slithering snake (injured) [dying] [5%].

The moblist contains: A mangy dog, A feral cat, etc.

I want the trigger to set the variable @curTarget to whatever the list matched.

I tried using a combination of %pos and %ismember, in an if statement, but nothing I tried got it to work properly.

Does anyone have a good solution to my trouble, please and thank you?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Feb 07, 2016 9:02 am   
 
#TRIGGER {^~(mob~)(@monsterNameList)} {curTarget=%1}
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Sun Feb 07, 2016 9:15 am   
 
Thanks for the lightning fast response, Vijilante, however that didn't work. I copied/pasted your trigger, and it fired on every single thing (I didn't have @monsterNameList defined) .. When I changed it to swampMobList, it just fails.

I already have another triggers using %ismember(@swampMobList) that works fine, so I know the list works. Any suggestions why this isn't working?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Feb 07, 2016 11:45 am   
 
Yes you were supposed to changes the variable name, I am not a mind reader and your original post did not contain the correct name so I could not put it in.

As long as you have the variable name spelled correctly it should find it and even automatically update the pattern whenever the variable changes. I am assuming this is CMud you are using since that is the forum you posted in, zMud would need a different tactic. You can check that the variable was found by looking at the pattern testing tab. Make sure you do not have a null item in the list, because if the null is first then it will always match that and set the capture to "".
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Sun Feb 07, 2016 11:57 am   
 
LOL I know you're not a mindreader, but when I copied and pasted it, that was my fault :) I just meant, that when I pasted it with the incorrect value, it would fire anytime it saw a mob, regardless of if it was in my list or not.

When I corrected it to use my list variable, it failed to match anything.

The current trigger is as follows.

<trigger priority="84310" id="8431">
<pattern>^~(mob~)(@swampMobList)</pattern>
<value>tell loftaris matched %1</value> <-- I just did this to show it's matching.. it never fires.
</trigger>

Yes, I am using CMud Pro on Windows 10. I tried editing the trigger, and manually pasting the trigger(edited) into the command line. Neither approach worked, it's not firing on the list. And the nul line was at the bottom, I removed it, and it still didn't help.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Feb 07, 2016 2:43 pm   
 
You will have to play with it using the compiled pattern and pattern test tabs to try to diagnose what is going on. I don't see any reason it would not be working which just leaves the contents of the variable.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Daern
Sorcerer


Joined: 15 Apr 2011
Posts: 809

PostPosted: Sun Feb 07, 2016 5:38 pm   
 
Try this: ^~(mob~)({@monsterNameList})
Reply with quote
shalimar
GURU


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

PostPosted: Sun Feb 07, 2016 6:01 pm   
 
Maybe the issue is that the list isn't properly delineated?


monsterNameList=%replace(@monsterNameList, ", ", "|")
_________________
Discord: Shalimar#3679
Reply with quote
Loftaris
Adept


Joined: 24 Aug 2004
Posts: 277

PostPosted: Sun Feb 07, 2016 7:35 pm   
 
Thank you Daern, and Vijilante. putting the list inside {} fixed the problem!
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