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
vimvam
Newbie


Joined: 03 May 2002
Posts: 2

PostPosted: Mon Apr 01, 2002 7:24 pm   

Can only get trigger to fire once per line...
 
Sorry for the double posts. I got to thinking that I may not be stating my problem clearly. I need to count the instances of a certain word in one line of output from my MUD. For example, if I see:

You also see an orc, an orc, and an orc.

And I set the following trigger:

#TR {orc} {#AD orcs 1}

...it will only fire once giving me an obviously inaccurate count of my enemies. I've tried any number of ways around this and cannot figure anything out. I can't really set the trigger to be more specific, because any number of things can be thrown in with the orcs.
Example:

You also see an orc, a broken bottle, an orc, some junk, another orc.

I am at my wits end.

One thing I don't understand, is that if I just set the trigger to color the word it will color all instances, but still only counts the word once.

Thx in advance
Jim
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Mon Apr 01, 2002 7:30 pm   
 
#TRIGGER {You also see (%*).} {#VAR numorcs %numwords( "%1", " orc")}

How about that? Assumes orcs always look
like " orc". This will catch orcfoo and
orcbar patterns though.



Ton Diening
Reply with quote
vimvam
Newbie


Joined: 03 May 2002
Posts: 2

PostPosted: Mon Apr 01, 2002 8:35 pm   
 
I am really about to kill myself with frustration. Good suggestion, but it's still not working exactly right.

Okay, this trigger:

#TR {You also see (%*).} {#VA enemiesinroom {%1}}

Takes this pattern:

You also see an orc, an orc, and some junk.

And sets @enemiesinroom to {an orc, an orc, and some junk}

So why, when I do: #SH %numwords(@enemiesinroom,orc)

...does it give me the number 3 every time?
Is there another command for returning the number of instances of a word in a string that I am missing?
Reply with quote
kognesty
Newbie


Joined: 08 Jan 2001
Posts: 8
Location: USA

PostPosted: Mon Apr 01, 2002 9:58 pm   
 
Well, I posted a solution to your troubles in the other post you made, but to explain why the thing you did failed is easy. %numwords counts the number of words in the string given according to a deliminator so %numwords( %1, orc) will count the number of words it catchs using orc as a means to seperate words, not as a means of how many times orc appears in the string. So a string containing orc twice will use orc as a deliminator twice and you'll get three words and two "spaces". In a string with only one orc, you'll get two words and one "space". Which could work if you always assume the number you get is one more then the actual number of orcs present.
Reply with quote
TonDiening
GURU


Joined: 26 Jul 2001
Posts: 1958
Location: Canada

PostPosted: Tue Apr 02, 2002 1:37 am   
 
Indeed. My logic mistake.

I forgot that stuff ORC stuff ORC stuff
would be counted as 3 things.

Ton Diening
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