Trigger on Colour

Posted by Drakonuz on Mon 08 May 2006 06:25 PM — 4 posts, 18,888 views.

#0
I've been searching this forum for a few days & cannot find where it says how to set up a trigger (in script) that will match colour.

I can make the trigger from the 'triggers' menu, but I want to set the trigger using AddTrigger and the help files don't show the options I need.

Input is something like the following:

!# cR Mana:Icy Move:Tired>
Harlond's Stable ##(coloured green)
An elven youth is busy attending to the animals.
Exits: east.

... and I want to be able to store the room name.
Australia Forum Administrator #1
You will need to use ImportXML to get at these options. See:

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

Make an example trigger in the GUI editor, to see the option names, and then use that as a template for the one you create in your scripting. If you were using Lua you could use the multi-line strings like this:


ImportXML [[
<triggers>
  <trigger
   back_colour="10"
   enabled="y"
   expand_variables="y"
   match="foo"
   match_back_colour="y"
   match_text_colour="y"
   send_to="1"
   sequence="100"
   text_colour="9"
  >
  <send>blah</send>
  </trigger>
</triggers>
]]


In JScript, just build up your XML text in whatever way you feel comfortable, and then call ImportXML to get MUSHclient to create the trigger. This particular example matches "foo" in red text (9) on a green background (10).
#2
I'm not very knowledgable in XML (and barely more at scripting). How would I embed this in my script file? For instance, if I have something like:

onPluginLoad

world.AddTrigger(doorOpened, * is opened *. | * opens the *., openReplace(%1,%2),eEnabled eIgnoreAliasCase eOmitFromLogFile eReplace eKeepEvaluating,"")
world.AddTrigger(doorClosed, * is closed *. | * opens the *., closeReplace(%1,%2), eEnabled eIgnoreAliasCase eOmitFromLogFile eReplace eKeepEvaluating,"")
world.AddTrigger(doorLocked, * locks the *. | * is locked *., lockedReplace(%1,%2), eEnabled eIgnoreAliasCase eOmitFromLogFile eReplace eKeepEvaluating,"")
world.AddTrigger(doorUnlocked, * unlocks the *. | * is unlocked *., unlockedReplace(%1,%2), eEnabled eIgnoreAliasCase eOmitFromLogFile eReplace eKeepEvaluating,"")
world.AddTrigger(doorPicked, You hear some clicking noises., pickedReplace(), eEnabled eIgnoreAliasCase eOmitFromLogFile eReplace eKeepEvaluating,"")


Would the XML just get pasted in here like:
ImportXML (
"<triggers>" +
"<trigger name="roomName" back_colour="10" text_colour="0" enabled="y" expand_variables="y" match="*" match_back_colour="y" match_text_colour="y" send_to="9" sequence="100" variable="rName">" +
"</trigger>" +
"</triggers>"
);

Or should I call it from somewhere?

Also, does the XML trigger language look correct? I assumed that using send_to=9 and varuable-rName would send the trigger value (the room name) to world variable "rName". Correct?
Australia Forum Administrator #3
Well, not quite because you have quotes within quotes, syntactically it is not correct JScript. This works:


ImportXML (
	"<triggers>" +
	"  <trigger" +
	"   back_colour=\"10\"" +
	"   enabled=\"y\"" +
	"   expand_variables=\"y\"" +
	"   match=\"*\"" +
	"   match_back_colour=\"y\"" +
	"   match_text_colour=\"y\"" +
	"   name=\"roomName\"" +
	"   send_to=\"9\"" +
	"   sequence=\"100\"" +
	"   text_colour=\"8\"" +
	"   variable=\"rName\"" +
	"  >" +
	"  <send>%0</send>" +
	"  </trigger>" +
	"</triggers>"
);


It looks more readable too because I have kept the line breaks.

Quote:

Also, does the XML trigger language look correct? I assumed that using send_to=9 and varuable-rName would send the trigger value (the room name) to world variable "rName". Correct?


For send to variable you need to specify *what* to send to the variable, so I have added %0 which is the entire matching text.

Anyway, I don't quite understand why you are doing this in onPluginLoad. You always want these triggers in a plugin, right? Why not just put the triggers in the plugin? Loading them each time from a script seems a roundabout way of doing it.

See the various plugins in the plugins section for examples. When you make a plugin with the plugin wizard any selected triggers (in your world file) are copied into the plugin, you don't need to add them with scripting.