[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Count multiple lines and then end
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Count multiple lines and then end

You need to log onto the forum to reply or create new threads.

  [Refresh] Refresh page


Posted by Rene   (22 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Rene   (22 posts)  [Biography] 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.
[Go to top] top

Posted by Marco   (36 posts)  [Biography] 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.
[Go to top] top

Posted by Marco   (36 posts)  [Biography] 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")
[Go to top] top

Posted by Rene   (22 posts)  [Biography] 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.
[Go to top] top

Posted by Marco   (36 posts)  [Biography] 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]
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] 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.


883 views.

You need to log onto the forum to reply or create new threads.

  [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]