Improve trigger copy without copying label

Posted by Zhenzh on Sun 22 Sep 2019 11:22 PM — 2 posts, 14,451 views.

China #0
when copying a trigger with label, it will failed for the label conflict. I have to additional operations remove label -> copy trigger -> add back label.

Actually, trigger label is not a necessary value to be copied. What we want is the other trigger options to be copied to created a similar trigger as the origanal one.

Copying label value seems a superfluous operation and will never get success. Can we using a null label instead of copying it during copying triggers?

Besides, why not using one button duplicate instead of copy/paste? The two buttons are always used one after another.
Australia Forum Administrator #1
Quote:

when copying a trigger with label, it will failed for the label conflict.


No, copying does not fail. Pasting an identical trigger fails.

Quote:

Actually, trigger label is not a necessary value to be copied. What we want is the other trigger options to be copied to created a similar trigger as the origanal one.


You may want that, however the copy/paste functionality is for more than merely duplicating a trigger. For example:

  • Copying a trigger from one world file to another
  • Copying a trigger from the GUI interface to a plugin
  • Copying a trigger from a world file to a forum posting


In all of these cases the trigger name is important, and might be part of the scripting, otherwise why have a name in the first place?

You can make yourself a "duplicate a trigger" alias like below, based on the "addxml" module described on this page:

http://www.gammon.com.au/forum/?id=7123

This lets you duplicate a named trigger. It finds the trigger, removes the name, and adds the new one into the world trigger space. Note that the inbuilt trigger adding code discards exactly duplicate triggers, which the code below checks for by making sure the number of triggers goes up.


<aliases>
  <alias
   match="duptrigger *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

require "addxml"  -- get extension script

if not GetTriggerInfo ("%1", 1) then
  ColourNote ("red", "", "Trigger '%1' does not exist")
  return
end -- if

-- get trigger
local t = addxml.save ("trigger", "%1")

-- get rid of label
t.name = ""

local count = #(GetTriggerList ())

-- put it back
addxml.trigger (t)

if #(GetTriggerList ()) ~= count then
  ColourNote ("green", "", "Trigger '%1' has been duplicated as an unlabelled trigger")
else
  ColourNote ("red", "", "Trigger '%1' not added, there must be an exact duplicate of it")
end -- if

</send>
  </alias>
</aliases>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.