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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Multiline triggers beginning with a prompt

Multiline triggers beginning with a prompt

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


Posted by Wink   (16 posts)  [Biography] bio
Date Tue 19 Apr 2005 05:50 AM (UTC)

Amended on Tue 19 Apr 2005 05:51 AM (UTC) by Wink

Message
My question is in regard to the effect of starting a multiline trigger with a prompt.

I've read many times that a great increase in efficiency can be obtained by lowering the sequence number of a basic prompt trigger. So by that I think I can assume that having a prompt trigger will overall have a noticeable slowing effect on how quickly everything is processed.

Here's my question:

If I start a bunch of multiline triggers with a prompt, will everything run slightly slower as a result? In other words, when the prompt line is received and then run through all the trigger lines for matches, will it catch on all those multiline triggers and slow down the trigger matching process as a result?

An example of one of these multiline triggers:

(\d+h\, .+)?\nYou give a fearsome roar\.\n\d+h\, \d+m


One situation where it would match:

1000h, 1000m -
You give a fearsome roar.
1000h, 1000m -



If anyone needs me to clarify what I mean, please just ask. (I'm actually getting a bit confused reading this myself, but I'm not sure how else to word it.)
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Tue 19 Apr 2005 07:32 AM (UTC)
Message
I do not think the saving you would get, if measurable, would outweigh the incredible increase in complexity by trying to combine a prompt trigger with every other possible one.

For one thing, you then have made every other trigger longer, so if anything it would make everything run slower.

Since the prompt is quite likely to occur, I would simply have the prompt trigger separate, and have a lower sequence number, so it gets checked first. Looking at the evaluation time for individual triggers you will probably fnd that the prompt trigger only take 1/1000 of a second to process, so it is hardly a big overhead to have it done first.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Wink   (16 posts)  [Biography] bio
Date Reply #2 on Tue 19 Apr 2005 09:02 AM (UTC)

Amended on Tue 19 Apr 2005 09:09 AM (UTC) by Wink

Message
Thanks for the prompt response, Nick.

I apologize, but I'm a bit unclear about what you mean. I think I may be guilty for a lack of clarity though.

What I'd be doing is creating approximately 10 to 15 of these ("prompt")?\n"abc"\n"prompt" triggers ("abc" being the line of output that I'm looking for). I wouldn't be eliminating my current single line prompt trigger, instead I'd want to search specifically for the "abc" output, and only respond if it is immediately preceded by either a prompt or blank line, and followed by a prompt.

In keeping with my previous example, I can do that in two ways, as I see it. Using the trigger:

You give a fearsome roar\.\n\d+h\, \d+m

I can match on:

You give a fearsome roar.
1000h, 1000m -

And then check if the line before "You give a fearsome roar." was a prompt or blank line.



Or, I can use:

(\d+h\, .+)?\nYou give a fearsome roar\.\n\d+h\, \d+m

To match:

1000h, 1000m -
You give a fearsome roar.
1000h, 1000m -

and/or

*blank line*
You give a fearsome roar.
1000h, 1000m -

The end result would be the same as far as I know, whichever method I choose. I'm not sure which of the two options would be more efficient, however.

Thanks in advance for any follow up response you can provide.

Edit: The reason I'm asking this is because making the three-line trigger is quite simple, whereas checking a few lines back for a match is pretty tough for me, as I'm rather inept when it comes to scripting.
[Go to top] top

Posted by Tsunami   USA  (204 posts)  [Biography] bio
Date Reply #3 on Tue 19 Apr 2005 11:56 AM (UTC)
Message
I think I understand what you want to do, but I'm not sure why you want to do it? Wouldn't it be easier to have 1 trigger for the prompt, and one trigger for the 'You give a fearsome roar.' bit? It comes to the same thing, neh?
[Go to top] top

Posted by Wink   (16 posts)  [Biography] bio
Date Reply #4 on Tue 19 Apr 2005 07:57 PM (UTC)
Message
Basically, my reasoning behind this is to limit the situations in which there would be a triggered response to the "You give a fearsome roar." line.

I'd want to respond to this:

1000h, 1000m -
You give a fearsome roar.
1000h, 1000m -


However, I would not want to respond to:

1000h, 1000m -
You tap your nose knowingly.
You give a fearsome roar.
1000h, 1000m -

1000h, 1000m -
You give a fearsome roar.
You tap your nose knowingly.
1000h, 1000m -

So if anything but a prompt/blank line precedes the "You give a fearsome roar.", or if anything but a prompt follows it, I want it to be ignored altogether. This is simply to prevent other people from fooling the system I'm using for a few select lines of output.

Hopefully that makes my motives a bit more clear.
[Go to top] top

Posted by Curious2   (47 posts)  [Biography] bio
Date Reply #5 on Fri 23 Jan 2009 07:40 PM (UTC)
Message
I hate to resurrect this old thread, but I am curious about this too.

I know what this guy is doing because I do it too and there is good reason, which I don't think you all understood.

The reason is to protect against illusions.

Certain things only happen procedeed by and followed by a prompt. However, a lot of people illusion stuff to fool you like illusion that you applied a defense and the defense came up at the same time between two prompts so then you really don't have the defense yet, but because you didn't make sure those lines have to be separate and proceeded and followed by prompts you think you do.

What is the best way to go about this? Will multiline triggers like that seriously slow you down? Could you do that in the trigger script instead? You want to make sure the line immediately proceeding the trigger and the line immediately following is a prompt just like he showed. I'm not sure how to do it either.

[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Fri 23 Jan 2009 09:02 PM (UTC)
Message
Multiline triggers won't slow things down a heap, except to the marginal extent that they are likely to be more complicated.

However I can't help thinking that this problem is better solved by a bit of trigger design. Otherwise (assuming you have lots of similar messages) they all have to be configured to have the exact prompt you use in each one, both before and after. If the prompt ever changes, then you have potentially hundreds of triggers to change.

How about, instead, a bit of "state machine" design? You have two things you want to trigger on, really:


  • A prompt
  • A message like "You give a fearsome roar." which may be an illusion if not directly preceded, and followed by, a prompt.


First, we note that GetLineCount will return the line number of the most recently-received line. Thus that identifies it uniquely.

http://www.gammon.com.au/scripts/doc.php?function=GetLineCount

Now let's proceed:


  • On receiving a prompt, we see if we have a stored message ("You give a fearsome roar." or whatever), and if the stored message is exactly one line number less than this (prompt) line. Then we know we have the case of message/prompt and we do whatever is required by the message. Then we delete the stored message.

    We also save the current line number as "the line number of the most recent prompt".

  • On receiving a message ("You give a fearsome roar." or whatever) we check the "the line number of the most recent prompt" is exactly one line number less than the current line. If so, we save this message for when the next prompt is received, along with its line number.

    Otherwise (if it is not directly after a prompt) we don't save the message, and indeed clear any saved message.


This should handle every case - the messages which are illusions will fail the "directly after the prompt" test, or "not directly followed by a prompt" test.

The amount of code would be small, there is only one handler for the prompts, and the various messages could share a single script routine.

If it is time to handle a non-illusion message, then a simple Lua table-lookup could map the message ("You give a fearsome roar.") to an appropriate function handler.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Curious2   (47 posts)  [Biography] bio
Date Reply #7 on Tue 03 Feb 2009 12:02 PM (UTC)
Message
Could you provide an example of this in code please? I think I have the idea but not sure.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Tue 03 Feb 2009 06:48 PM (UTC)
Message
How about you try and see if you can make it work? As I suggested above you need two triggers, one for the prompt and one for the "fearsome roar" line.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Curious2   (47 posts)  [Biography] bio
Date Reply #9 on Wed 04 Feb 2009 05:02 AM (UTC)
Message
I already did make it work. :-)

I just created a table made the key the string and line number the value. I then stored prompt line number in a variable. At the prompt I just check the table length and if anything is there loop through it and do whatever based upon the key and if the value is 1 less than the prompt number. Then I clear the table.

I was just wondering if you had some fantastic way of doing it much more smoothly.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Wed 04 Feb 2009 05:26 AM (UTC)
Message
Your way is different to what I suggested, but there are usually lots of ways of doing things. If it works, I wouldn't worry.

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


26,854 views.

It is now over 60 days since the last post. This thread is closed.     [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 HostDash]