Multi-line triggers in Dummy Windows

Posted by Tsheller on Fri 05 Sep 2008 06:13 AM — 11 posts, 35,959 views.

USA #0
Thanks to the wonderful FAQ, I've worked out the details of my first 'plugin' that does -almost- everything I've wanted it to do. Big thanks to Nick for the help.

I know this is a really stupid question, but hopefully its easy for someone to answer.

I currently have an alias to turn off and on the two triggers I am using for my plugin, but I would also like to echo in my window that I have done such, just for completeness sake.

One of the aliases looks as follows:

<alias
name="chatsoff"
match="chatsoff"
send_to="12"
enabled="y"
sequence="100"
>
<send>
EnableTrigger ("chats_trigger1", false)
EnableTrigger ("chats_trigger2", false)

</send>
</alias>

What would I need to add to make it echo a simple message saying 'chats window has been turned off', I am only assuming at this point that the send_to="12" is referring to the lua scripting stuff built into MUSCHclient..
Amended on Fri 05 Sep 2008 06:14 AM by Tsheller
USA #1
Note("Chats are disabled.")


(world.Note() for non Lua scripts)
Amended on Fri 05 Sep 2008 06:23 AM by WillFa
USA #2
I knew it was easy, regardless, you rock my socks.
USA #3
You're welcome. :) And, send_to="12" means you have "Send to: Script" selected.
Australia Forum Administrator #4
The 'world.' part is optional for most script engines. MUSHclient tells the Windows Script Interface that "world" is the default namespace, so in most cases (eg. VBscript) you can omit it. An exception (in VBscript) is Execute because there is a VBscript Execute function.
USA #5
Yeah, its working beautifully. Until we have scrolling miniwindows, the dummy window will work really well. I am not even sure if I will use a miniwindow even if it becomes available because I have had such a tough time with it.

This may be the wrong forum, but is there a somewhat easy way to replace the dummy window with a miniwindow?

Also, I've been having a bit of trouble. I'm not sure if its just a limitation of the presented output, but when the group command is called, I am only able to (currently) detect the . denoting the last member of the group, then its a blank line, then the prompt. Something like this:

A crazy-eyed woman [******] (guarding) (guarded), leading:

a wheat-haired man [******] (guarding),
a comely-faced man [******] (guarded),
a golden-haired man [******],
a lithe man [******].

<prompt>

It also has the quirk of capturing everything until the first timer of group executes, I am fairly sure just making it also send the group command when I type chatson will be an easy work around though.

So, is there a better way I could be using triggers to deal with the blank lines. I've included the plugin thusfar below.


The code



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, June 30, 2007, 10:48  -->
<!-- MuClient version 4.13 -->

<!-- Plugin "Chat_Redirector" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Chat_Redirector"
   author="Nick Gammon"
   id="cb84a526b476f69f403517da"
   language="Lua"
   purpose="Redirects Things and Notifies to Another window"
   date_written="2007-06-30 10:45:35"
   requires="4.08"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Redirects Triggered Info to another Window named soichats
]]>
</description>

</plugin>

<!--  Triggers  -->

<triggers>
<!-- Captures Notify message and sends it to dummy world via redirect script -->
  <trigger
   name="chats_trigger1"
   enabled="y"
   match="^[(.*?)$"
   regexp="n"
   script="redirect"
   sequence="100"
  >
  </trigger>

<!-- Captures Triggering Group message and toggles milti_line_chat trigger if applicable -->
  <trigger
   name="chats_trigger2"
   enabled="y"
   match="^(.*?) leading\:$"
   regexp="y"
   omit_from_output="y"
   script="redirect"
   sequence="100"
  >
  </trigger>

  <trigger
   enabled="n"
   match="*"
   script="redirect"
   omit_from_output="y"
   name="multi_line_chat"
   sequence="10"
  >
  </trigger>


</triggers>

<!-- Aliases -->
<aliases>
  <alias
   name="chatson"
   match="chatson"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>
EnableTrigger ("chats_trigger1", true)
EnableTrigger ("chats_trigger2", true)
EnableTrigger ("multi_line_chat", true)
EnableTimer ("group", true)
Note("Chats are Enabled.")

</send>
  </alias>

  <alias
   name="chatsoff"
   match="chatsoff"
   send_to="12"
   enabled="y"
   sequence="100"
  >
  <send>
EnableTrigger ("chats_trigger1", false)
EnableTrigger ("chats_trigger2", false)
EnableTrigger ("multi_line_chat", false)
EnableTimer ("group", false)
Note("Chats are Disabled.")

</send>
  </alias>

</aliases>
<!-- End Aliases -->

<!-- Timers -->
<timers>
  <timer 
      name="group"
      enabled="y" 
      second="10.00" 
      omit_from_output="y"
      >
<send>
group
</send>
  </timer>
</timers>


<!--  Script  -->


<script>
<![CDATA[
chat_world = "soichats"
local first_time = true

function redirect (name, line, wildcards, styles)

  -- try to find "chat" world
  local w = GetWorld (chat_world)  -- get "chat" world

  -- if not found, try to open it
  if first_time and not w then
    local filename = GetInfo (67) .. chat_world .. ".mcl"
    Open (filename)
    w = GetWorld (chat_world)  -- try again
    if not w then
      ColourNote ("white", "red", "Can't open chat world file: " .. filename)
      first_time = false  -- don't repeatedly show failure message
    end -- can't find world 
  end -- can't find world first time around

  if w then  -- if present
    for _, v in ipairs (styles) do
      w:ColourTell (RGBColourToName (v.textcolour), 
                    RGBColourToName (v.backcolour), 
                    v.text)  
    end -- for each style run
    w:Note ("")  -- wrap up line

  end -- world found

  -- if ends with quote, end of multi-line chat
  if line:sub (-1) == '"' then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go
  else
    EnableTrigger ("multi_line_chat", true)  -- capture subsequent lines
  end -- if

  -- if ends with . end of multi-line chat
  if line:sub (-1) == '.' then
    EnableTrigger ("multi_line_chat", false)  -- no more lines to go
  else
    EnableTrigger ("multi_line_chat", true)  -- capture subsequent lines
  end -- if 

end -- function redirect 

]]>
</script>
</muclient>
Amended on Fri 05 Sep 2008 08:16 AM by Tsheller
USA #6
  match="^[(.*?)$"
   regexp="n"


That won't work. It looks like half of a regular expression, but regular expressions aren't turned on.

Also, the ^ in the first position means to match at the start of the line. none of your sample output actually starts with a "[", although with Regular Expressions turned on, you'd need to escape it, "[" so that it literally means an open bracket. With Regular expressions, brackets are reserved for classes. [0-9] means any single digit in that range, for example.

Check out the Regular Expression Syntax link on the main forum page. http://www.gammon.com.au/mushclient/regexp.htm

"^([^[]++)[\*++]\((?:guarding|guarded)?[ ,\.])+(?:leading\:)?$"

Is a pattern that should match your sample output.

The trigger 'multi_line_chat' grabs everything and anything. Would you like to be a little more discriminating? :)

Ummm... I'm tired, sorry if that's not as helpful as I'd like.

USA #7
*mutter* This is what I get when scripting at 4am ;)

No, you are being a great help. Fact is, what that other trigger is trying to grab isn't important, I was just trying to get output just to see the darn thing work, but now that it is, fixed that part. The text that it is looking to match is

[A yellow-painted volkswagon beetle (The Autobots) is online.

Again, when either someone shows me or I figure it out, I will probably try to do some formatting to arrange those who have recently notified by their group (The Autobots) of those who notified within the last hour or something.

As far as the multi_line_chat goes, I am not sure how else to grab everything while still being discriminating. It -would- be neat to grab names, and then arrange them by their health with some sub headings like.

Group:

Healthy (at and 4 stars)
-
Injured (below 4 stars)
-
Critical (at and below 2 stars)
-

Oh yeah, even though its a dummy window, is there a way to actually Replace what is in the screen rather than append? Its looking more and more like I need to take another stab at Miniwindows, but this is working for now.

-- Added

The regular expression you gave me is returning..

Line   40: Error "Failed: unmatched parentheses at offset 44" processing regular expression "^([^[]++)[\*++]\((?:guarding|guarded)?[ ,\.])+(?:leading\:)?$" (trigger not loaded)
Amended on Fri 05 Sep 2008 10:57 AM by Tsheller
Netherlands #8
He made a small typo: ^([^[]++)[\*++]\((?:guarding|guarded)?[ ,\.]\)+(?:leading\:)?$
USA #9
Gonna resurrect this since I've had only marginal results with my own testing.

I have having some trouble with the above plugin. It doesn't seem to be discreet enough to only capture the desired text. I am not sure if the problem is just that I do not have anything more exact to trigger on or if there is a better way. Anyone have some ideas or advice on how to make this work better?

thanks.
Australia Forum Administrator #10
What I suggest you do is turn on Trace mode (Game menu -> Trace).

That will tell you when triggers / aliases fire. Judging by what I have seen above maybe one of your triggers should be normally disabled, and only enabled when necessary.

Using trace, you can say to yourself "that trigger fired, but it shouldn't have - why is that?", or "that trigger didn't fire, but it should have - why is that?".