Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Perlscript ➜ Add Trigger Information Sought

Add Trigger Information Sought

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


Posted by Kaye Mason   (4 posts)  Bio
Date Thu 11 Sep 2003 08:52 PM (UTC)
Message
I'm just starting out scripting for MUSH Client, and using perl, which I'm at least slightly familiar with. I've been trying to write a simple script to run a command, read the outupt, and do something with it.

Everything seems happy so far, but I'm wondering if someone can explain the meaning of some of the extra bits of AddTrigger. I just don't understand a few things. Like the constants from the help file:

--------------------------------------------
my $eEnabled = 1; # enable trigger
my $eOmitFromLog = 2; # omit from log file
- I assume I understand these.

my $eOmitFromOutput = 4; # omit trigger from output
- Erm...does this mean that my $world->sends won't work?
my $eKeepEvaluating = 8; # keep evaluating
- Keep evaluating which? The code after the add trigger? The trigger after it's hit once? I'm not sure what to make of this.

my $eIgnoreCase = 16; # ignore case when matching
- Simple enough

my $eTriggerRegularExpression = 32; # trigger uses regular expression
- Inside the trigger, I imagine, and not in whatever script function my trigger is callign?

my $eExpandVariables = 512; # expand variables like @direction
- I've no idea what this means, nor what @direction is.

my $eReplace = 1024; # replace existing trigger of same name
my $eTemporary = 16384; # temporary - do not save to world file
- I think I understand these.
----------------------------------------

AddTriggerEx, at least in the documentation, doesn't have a constant for "Send To Script" like DoAfterSpecial. Is this correct, or if I use the "12" constant listed in DoAfterSpecial, will it work? How is this different than using the ScriptName parameter at the end of AddTrigger?

------------------------------------------

Wildcard -- this doesn't seem to behave in any way as I would expect. I assume it means that if my "MatchText" is "Text * text *", that if I put '2', my ScriptName will get the second * in @_. In fact, when I go to my ScriptName, I get $_[0] as the trigger name, and $_[1] as the full line of text that triggered the trigger. I can deal with that, I'm just wondering if someone can tell me what Wildcard does, if it's not what I thought it was?

-----------------------------------------------------

I think that's it for now -- sorry to be so much trouble. I'm sure if I understood perl, and scripting for MUSHClient better, I'd be able to work it out on my own. Thanks!

Cheers,
Kaye
Top

Posted by Shadowfyr   USA  (1,790 posts)  Bio
Date Reply #1 on Thu 11 Sep 2003 09:48 PM (UTC)
Message
> my $eOmitFromOutput = 4; # omit trigger from output
> - Erm...does this mean that my $world->sends won't work?

This Omits the 'original' text. It has no effect on send and is used either to gag a line or in cases where you want to respond to the contents, but not actually see it. I use it this way in the case of my Druid Potion plugin for Ages of Despair. The plugin activates a trigger to capture lines and look for the end line of the inventory, then executes an 'inventory' command. It then captures each line and looks for herbs, but none of the lines are actually visible. Then another trigger sees the final inventory line (which is also omitted) and turns off itself and the capture one. The only thing I see in output is the 'i' command and a list of potions I can make that is generated by matching the final inventory line.

> my $eKeepEvaluating = 8; # keep evaluating
> - Keep evaluating which? The code after the add trigger? The trigger after it's hit once? I'm not sure what to make of this.

The line itself. Any line that is matched once will be ignored by all other triggers. This option allow you to tell Mushclient that more than one trigger may be matching the same line.

> my $eTriggerRegularExpression = 32; # trigger uses regular expression
> - Inside the trigger, I imagine, and not in whatever script function my trigger is callign?

Yes. Regular expressions in your script are handled by a special script command. This is only for the trigger itself, not any output is generates of scripts it calls.

my $eExpandVariables = 512; # expand variables like @direction
- I've no idea what this means, nor what @direction is.

This is for cases where you want to make a trigger match on something that is unknown before hand. For instance, you might have an alias that does:

alias: setdir *
<script>
setvariable "direction","%1" 'This is VB of course.
</script>

Then a trigger that does:

Match: @direction
color: red
expandvariables: yes

If you then typed 'setdir up', the trigger would automatically match on every instance of 'up' and color it red. This is more commonly used in the past for combat, where you set a @target variable and have other aliases for attacks, or triggers to follow the mob, respond to the contents of the @target variable as though the aliases and triggers actually had that mobs name in them.

> AddTriggerEx, at least in the documentation, doesn't have a constant for "Send To Script"...

Unfortunately some features where added 'after' the introduction of AddTriggerEx and similar commands. It also lacks the ability to correctly recognize the custom_color setting, though I am still not clear why adjusting the allowed values by one, when the option name itself is accessable wasn't done. These features require using SetTriggerOption (I think the command is). Newer versions are apparently going to use XML_Import or some such, but I am not sure how much of an improvement that would be if you tried to make a quick trigger by typing in the options on the command line. lol

> Wildcard -- this doesn't seem to behave in any way as I would expect. I assume it means that if my "MatchText" is
> "Text * text *", that if I put '2', my ScriptName will get the second * in @_. In fact, when I go to my ScriptName, I
> get $_[0] as the trigger name, and $_[1] as the full line of text that triggered the trigger. I can deal with that,
> I'm just wondering if someone can tell me what Wildcard does, if it's not what I thought it was?

Not sure what you mean here.. Wildcards 'should' work like this:

0..: The line matched.
1-9: You * parts
10.: Don't remember..

So with a trigger like:

Fred says: *

and a line like:

Fred says: Hello!

You should get:

0..: Fred says: Hello!
1..: Hello!
2-9: Empty
10.: ??

I could have 10 and 0 confused though, I can never bloody remember what they are supposed to do. However, I seem to remember there veing something odd about wildacards and Perl, but I could be wrong. Like you have to convert them to a VBArray type, before you can correctly get there contents... Can't remember, since I don't actually use Perl.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 11 Sep 2003 10:46 PM (UTC)
Message
The simple way to understand the flags for AddTrigger is just to look at the documentation for triggers in general:

http://www.gammon.com.au/scripts/doc.php?dialog=IDD_EDIT_TRIGGER

Basically the flags in AddTrigger are bit representations of the checkboxes in the trigger dialog. If you know what they do, the flags make sense.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Kaye Mason   (4 posts)  Bio
Date Reply #3 on Thu 11 Sep 2003 10:49 PM (UTC)
Message
Thank you! That's extremely helpful. I think I understand all the flags now, for the most part.

Still a little confused on $eExpandVariables, perhaps because I don't understand visual basic script at all. I don't know what an alias is, nor what %1 is (unless you're talking on the game, which would mean they're entirely different from what I'm thinking!), and how those equate to perl constructs (sorry, I'm only just learning perl, I can't make the leap yet :}).

I'm also still confused about the wildcard bit. Perhaps if I make it more concrete, it will help.

Suppose I have my subroutine:

sub myTest {
my ($command) = @_;

$world->AddTrigger($command, #name
"text0 * text1 * text2", # match text
1 | 512 | 16384, # flags
-1, # colour,
"", # sound
"ParseValue"); # my script

$world->send($command);
}

As I understand it, this should send $command to my world, and wait for the response "text0 * text1 * text2". It will replace any existing trigger for $command, not save to the world file, and be enabled. Now, in my "ParseValue" script, I want to be able to access the wildcard stuff. Suppose I'm only interested in the wildcard between 'text1' and 'text2'. I've set the "WildCard" parameter to "2" to indicate that I'd like that preserved.

sub ParseValue{
my ($input) = @_;
}

If this is ParseValue, how should I access that wildcard? My @_ seems to be an array that looks like (replace <> with described item):

@_ = { <$command>, <the original string from the game>, ARRAY(0x2b6dcec) }

Once again, thanks very much for your help -- very useful.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Thu 11 Sep 2003 10:50 PM (UTC)
Message
Quote:

my $eExpandVariables = 512; # expand variables like @direction
- I've no idea what this means, nor what @direction is.


Also you can match variables in the sent text.

eg. if you had a variable "target" and it was currently "kobold" (you can set that up manually in the variables configuration screen, or in other ways, eg. by an alias) then you can make a trigger like this:

Match: The @target exits *
Send:

go %1
punch @target

If "expand variables" is checked then "@target" in both the match and sent text is replaced by kobold.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Kaye Mason   (4 posts)  Bio
Date Reply #5 on Thu 11 Sep 2003 10:53 PM (UTC)
Message
Sweeeeeeeeeeeet, Nick. Thank you, that's exactly what I needed! Thank you both for your awesome help!
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Thu 11 Sep 2003 11:13 PM (UTC)
Message
Quote:

As I understand it, this should send $command to my world, and wait for the response "text0 * text1 * text2".


Not exactly. A trigger waits for the trigger text and then sends the response, not the other way around.

An alias matches something *you* type, a trigger matches something from the MUD.

Thus you might make an alias:

Match: dw
Send: drink water

That is so you can type "dw" and have it do "drink water".

As for wildcards, maybe you want to drink other things:

Match: d *
Send: drink %1

That says you can type "d wine" and it will send "drink wine". This is because %1 matches wildcard 1 (ie. the first asterisk).

Similarly with triggers. I would normally enter triggers manually (in the GUI interface) because scripted trigger entry is something normally reserved for special cases where you need to make triggers on-the-fly.

As for getting wildcards inside a trigger script, this example script from the exampscript.pl file (shipped with the program) shows the general idea ...


# --------------------------------------------
# Example showing a script called by a trigger
#  Should be connected to a trigger matching on: <*hp *m *mv>*
#   (the above example will work for SMAUG default prompts (eg. <100hp 10m 40mv>)
#    it may need to be changed depending on the MUD prompt format).
# --------------------------------------------
sub OnStats
{
my ($strTriggerName, $trig_line, $wildcards) = @_;

$iHP = $world->GetTriggerInfo ($strTriggerName, 101);
$iMana = $world->GetTriggerInfo ($strTriggerName, 102);
$iMV = $world->GetTriggerInfo ($strTriggerName, 103);

$world->Note ("Your HP are $iHP");
$world->Note ("Your Mana is $iMana");
$world->Note ("Your movement points are $iMV");

}	# end of OnStats 


- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


20,183 views.

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

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.