AddTrigger, Repeat on same line.

Posted by Jiffies Maloye on Sat 08 Feb 2003 10:34 PM — 11 posts, 37,535 views.

Sweden #0
The scripting function AddTrigger misses a key function .. repeat on same line .. am i the only one missing it ?
i need it for my scripting >.< (using a who command on a muck to gather nicks and then generating a regex trigger (Name,Name1,Name2), thus the repeat on same line would be nice to have)

//Jiffies ( nilspe_80(AT)hotmail(dot)com )
USA #1
Check at:

http://www.gammon.com.au/scripts/function.php

Specifically this one:

http://www.gammon.com.au/scripts/function.php?name=AddTriggerEx

The help files that come with Mushclient are incomplete do to a lot of things getting added and changed rapidly in the last half dozen versions.
Australia #2
I have recently attempted to make a similar thing, a plugin to colour names that generates triggers on startup using any number of lists each stored in a variable (user may manage and modify easily via a few alias commands).

I had been using Repeat on same line in testing, using triggers made via the GUI, and now in the move to AddTriggerEx I also find myself unable to locate this particular flag.

My trigger_flag table contains,
Enabled=1
OmitFromLog=2
OmitFromOutput=4
KeepEvaluating=8
IgnoreCase=16
RegularExpression=32
ExpandVariables=512
Replace=1024
LowercaseWildcard=2048
Temporary=16384

which is the same as is listed in the documentation.

Suppose following with a SetTriggerOption("thetrigger","repeat",1) should be good enough?

Just curious to know if I have missed something. :)
Australia Forum Administrator #3
Quote:

Suppose following with a SetTriggerOption("thetrigger","repeat",1) should be good enough?


Yes, this is one way of doing it. It is not in the list of flags handled by AddTrigger or AddTriggerEx.

This is an example of how the client has evolved. If I was writing another way today I would stick to one simple system of setting options.

If you want to add triggers (or other things) quickly and easily you might consider using ImportXML:

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

The processing for ImportXML is exactly the same as what MUSHclient uses to load triggers (etc.) when loading up a world, and thus will support all available options.


ImportXML [[
<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="blah"
   regexp="y"
   repeat="y"
   sequence="100"
  >
  </trigger>
</triggers>
]]


The advantage of this is it is more readable, all options are supported, and you do the whole thing in one operation.

Of course, the parts that change will be done as variables (eg. using string.format).
Australia Forum Administrator #4
Here is an example of using ImportXML with variables, and checking the import:


matchtext = "cake"
sequence = 90

assert (ImportXML (string.format ([[
<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   match="%s"
   regexp="y"
   repeat="y"
   sequence="%i"
  >
  </trigger>
</triggers>
]], 
  matchtext,   -- what to match on
  sequence     -- sequence number
  )) == 1)     -- should import exactly one thing

Australia Forum Administrator #5
Follow this link for a method to simplify the whole thing. This takes a technique described in the Lua manual, to make a function take "named" arguments (by putting them in a table). This simplifies doing your own AddTrigger, and allows for all possible options:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=7123

The example at the end shows how you can call MyAddTrigger using any of the possible keywords supported by the XML code. It automatically turns true and false into "y" and "n" to make it look a bit more natural. It also handles the cases of something like a quote symbol being inside (say) the match text.

Amended on Fri 23 Jun 2006 03:57 AM by Nick Gammon
Australia #6
Thanks, that has been a great help.

But I have run into a problem with the imported triggers.

My alias for changing the other_text_colour and the back colour gsubs them into the particular list variable, and uses
SetTriggerOption("%<list>","other_text_colour",utils.split("%<args>"," ")[1])


An example of use, name:colour aList aFrontColour aBackColour

The names are only coloured by the new colours if the plugin is reloaded (so the triggers are rebuilt from ImportXML using the new colours recently stored in the variable).

I don't quite understand, as I can modify the match field of the triggers, and the recently added or removed name is coloured (or is not as required) without having to reload anything.

Since I have the same issue trying to modify the other colours of triggers in the world space, I suspect the problem lies in my SetTriggerOption calls. I am not sure how else to pass the colour if that is incorrect.
Australia Forum Administrator #7
You may have found a bug. Can you copy the offending trigger (the one that doesn't work) and paste the XML code here please?
Australia Forum Administrator #8
Quote:

SetTriggerOption("%<list>","other_text_colour",utils.split("%<args>"," ")[1])


I'm not really following how this works. Can you paste the whole alias?
Australia #9
Alrighty.

First up,
<triggers>
  <trigger
   custom_colour="17"
   enabled="y"
   match="match this"
   name="testtrigger"
   sequence="1"
   other_text_colour="mistyrose"
  >
  </trigger>
</triggers>


/SetTriggerOption("testtrigger","other_text_colour","green") at the command line does not appear to change the trigger.


As for my alias, it may appear somewhat convoluted.. I thought one would be neater, but as it grows it may be best to split or feed into a function. I removed the code from the other else/ifs for clarity, and they work as expected.

<aliases>
  <alias
   match="^name:(?P&lt;cmd&gt;(add|remove|colour|show|createlist|deletelist)) (?P&lt;list&gt;\w+)(| (?P&lt;args&gt;.+))$"
   enabled="y"
   regexp="y"
   send_to="12"
   sequence="1"
  >
  <send>if "%&lt;cmd&gt;"=="add" then
 -- add name
elseif "%&lt;cmd&gt;"=="remove" then
 -- remove name

elseif "%&lt;cmd&gt;"=="colour" then
 SetTriggerOption("%&lt;list&gt;","other_text_colour",utils.split("%&lt;args&gt;"," ")[1])
 SetTriggerOption("%&lt;list&gt;","other_back_colour",utils.split("%&lt;args&gt;"," ")[2])
 SetVariable("%&lt;list&gt;",string.gsub(GetVariable("%&lt;list&gt;"),"^[#%a%d]+|[#%a%d]+",utils.split("%&lt;args&gt;"," ")[1].."|"..utils.split("%&lt;args&gt;"," ")[2],1))
 Note("Changed colour of: ".."%&lt;list&gt;"..", to "..utils.split("%&lt;args&gt;"," ")[1].." on "..utils.split("%&lt;args&gt;"," ")[2]..".")

elseif "%&lt;cmd&gt;"=="show" then
 -- show names in list
elseif "%&lt;cmd&gt;"=="createlist" then
 -- create variable and trigger
elseif "%&lt;cmd&gt;"=="deletelist" then
 -- delete variable and trigger
end</send>
  </alias>
</aliases>


Using say, name:colour friends yellow #FFFFFF does not modify the trigger, but the confirmation Note is shown.

The variable structure is simply "frontcolour|backcolour|player|anotherplayer|etc" where the name is the list it represents.
Amended on Fri 23 Jun 2006 09:13 AM by Cino
Australia Forum Administrator #10
Quote:

/SetTriggerOption("testtrigger","other_text_colour","green")


It helps in situations like this to print the return code. Many functions return a code to indicate success or failure. Let's try that:


print (SetTriggerOption("testtrigger","other_text_colour","green")) --> 30026


A code of other than zero from this function means failure, so you can see that the colour won't change. You can find the exact meaning a number of ways. One neat way is to use the "check" function supplied in the example Lua script file:


check (SetTriggerOption("testtrigger","other_text_colour","green")) --> New value for option is out of range


Or, you could do this:


/print (error_desc [30026]) -> New value for option is out of range


Now what is out of range about "green"? Let's see what it was before we changed it:


print (GetTriggerOption("test","other_text_colour")) --> 4678655


Aha! It printed a number, thus the colour is an RGB one, not a name. Thus your solution is to do this:


SetTriggerOption("test","other_text_colour", ColourNameToRGB ("green"))


I admit the documentation does not specifically say what sort of colour it is, I will amend that.