Count multiple lines and then end

Posted by Rene on Mon 16 Oct 2017 11:02 PM — 8 posts, 32,975 views.

#0
The MUD on 'locate' command returns a line for the location of each one of the items, for example 'locate swords' will return:
"The sword is lying on the ground.
The sword is in your backpack.
The sword is in your backpack.
The sword is in your left hand."
I want to count how many swords there are, and have it stop counting immediately so that it shouldn't mistake another line or a repeat command as more swords. How would you suggest doing this?

Thanks.
Australia Forum Administrator #1
Use an alias to do the "locate" for you, which zeroes a counter, and turns on a trigger (enables it) which matches:

"The sword is *"

That trigger can add one to the counter.
Also have a second trigger higher in sequence (so it matches later) which matches anything (ie. "*") and prints the counter. eg.


The sword is lying on the ground.  --> add 1 to counter
The sword is in your backpack.     --> add 1 to counter
The sword is in your backpack.     --> add 1 to counter
The sword is in your left hand.    --> add 1 to counter
The rain gets heavier.   --> Display that there are 4 swords


This second trigger also disables itself, so that it doesn't display the count for all subsequent lines.
#2
Was thinking of that, I'm sure it is simple, but how do I have the trigger disable itself? I'd set it to enabled and have the script it runs disable it? What is the syntax to have a trigger disable itself?
I'm kind of new, I can manipulate examples but have a hard time starting from scratch.
Thanks.
Amended on Tue 17 Oct 2017 06:11 AM by Rene
#3
**** Edited & Amended (see following post) ****

Rene said:

Was thinking of that, I'm sure it is simple, but how do I have the trigger disable itself?


It's enough you put in the script of the second trigger
EnableTrigger ('mytrigger', false)

(remember you have to check Send To Script in the send box, that usually is set to Send To World
by default, if i remember correctly
)

Where 'mytrigger' is the name you choose for your trigger.

As regarding the regular expression to set the initial alias (the one who start the locate instruction) you could use something like..
 ^ll\s(.*?)$ 
and (in the send box)
cast 'locate' %1

In this case Send To have to be set to World and the option (on the right) Regular Expression have to be checked.
Using regular expressions let you be more accurate regarding how the alias work.

In that case only a statement stating from the beginning of the row with an ' ll ' , followed by a space and then by the name of the object will start the alias.
Amended on Tue 17 Oct 2017 11:03 AM by Marco
#4
Marco said:

As regarding the regular expression to set the initial alias (the one who start the locate instruction) you could use something like..
 ^ll\s(.*?)$ 
and (in the send box)
cast 'locate' %1

In this case Send To have to be set to World and the option (on the right) Regular Expression


UNFORTUNATELY I have to correct myself..

The alias who locate the object has to activate the trigger and set the counter = 0.

Therefore the alias has to contain script and the send Box has to be SendTo Script.

Accordingly in the Send windows the code will be:
EnableTrigger ('mytrigger', true)
Counter = 0
Send("cast 'locate' %1")
#5
Thanks, is there a way to match specifically multiple lines in a trigger?
Something like:
(^The sword is in .+.$\n){1,30}

And then it will only fire at the end? I've tried running it like that and it still matches on only a single line.
#6
Rene said:

Thanks, is there a way to match specifically multiple lines in a trigger?

Yes, it's possible though i think your example is not completely correct.

Also sorry if i put only fragment here and there witout giving you a complete tested solution but from here (...) it's impossible for me to make such a thing.

For multi-line trigger Nick Gammon (Admin) covered the issue Also somewhere in the 'Separate Chat Window' topic

[forum=7991]
Amended on Wed 18 Oct 2017 12:37 PM by Marco
Australia Forum Administrator #7
Rene said:

Thanks, is there a way to match specifically multiple lines in a trigger?


Template:faq=37
Please read the MUSHclient FAQ - point 37.


Trying to do it with a single multi-line trigger can be fiddly.

Your example of "up to 30" matches would, of course, fully match after a single line. You would need to somehow know what is going to be on the 31st line (or whatever number) in order to terminate the match, but not prematurely.