Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ Count multiple lines and then end

Count multiple lines and then end

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Rene   (46 posts)  Bio
Date Mon 16 Oct 2017 11:02 PM (UTC)
Message
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.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 17 Oct 2017 04:48 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Rene   (46 posts)  Bio
Date Reply #2 on Tue 17 Oct 2017 05:32 AM (UTC)

Amended on Tue 17 Oct 2017 06:11 AM (UTC) by Rene

Message
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.
Top

Posted by Marco   (36 posts)  Bio
Date Reply #3 on Tue 17 Oct 2017 06:28 AM (UTC)

Amended on Tue 17 Oct 2017 11:03 AM (UTC) by Marco

Message
**** 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.
Top

Posted by Marco   (36 posts)  Bio
Date Reply #4 on Tue 17 Oct 2017 10:41 AM (UTC)
Message
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")
Top

Posted by Rene   (46 posts)  Bio
Date Reply #5 on Wed 18 Oct 2017 06:06 AM (UTC)
Message
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.
Top

Posted by Marco   (36 posts)  Bio
Date Reply #6 on Wed 18 Oct 2017 10:05 AM (UTC)

Amended on Wed 18 Oct 2017 12:37 PM (UTC) by Marco

Message
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]
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #7 on Wed 18 Oct 2017 08:24 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


22,911 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.