Help with my first simple trigger?

dss
Posts: 12
Joined: Tue Apr 13, 2010 4:17 pm

Help with my first simple trigger?

Post by dss »

Hi, I'm new here and I'm really confused about triggers.

I'm trying to write a simple autofollow script and I'm not making any progress at all.

if this is what I'm trying to accomplish

Harry leaves sw
sw

(*.) leaves (*.); (*.)

I am not a coder of any kind and as I read the manual I see how certain things can be done, but my head quickly begins to hurt and I get confused.

Can someone please assist me in learning the very basics of how to create a trigger like this?

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Help with my first simple trigger?

Post by demonnic »

ok, so you're trying to follow someone when they leave in a certain direction? IOW, if you get


Harry leaves sw.

you want to follow harry sw?

if that's the case, you'll want a perl regex trigger:

^(\w+) leaves (\w+)\.$

and the code it will execute is

send(matches[3])


if you want it to check if the person who left is your target, if you could do

if matches[2] == target then send(matches[3])


if you're variable name for your target is "target"

dss
Posts: 12
Joined: Tue Apr 13, 2010 4:17 pm

Re: Help with my first simple trigger?

Post by dss »

Hi, and thank you so much for your reply. I'm learning already.

So I opened the trigger panel.
I created a new trigger and called it "auto follow"
I entered "^(\w+) leaves (\w+)\.$" into the first section (0) and set it to "perl regex"
I saved it.

I am clearly missing something important about how to create and use a trigger because when Harry leaves sw, he's gone and I don't follow him.

I would love to be able to "target" harry, so I don't follow anyone else, and I would also love to be able to follow n,s,e,w,sw,se,nw,ne, up, and down.

But I'm definitely missing something very important about how to create and apply a trigger. For example, what do I put into "send plain text" ? I think, as appears to be true as I read the manual, that I need an even simpler guide to how to create a trigger.

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Help with my first simple trigger?

Post by demonnic »

nothing goes in 'send plain text' as you need something slightly more complex than that. What you put in the big white box beneath is

send(matches[3])

which will then go sw. This is all assuming the message "Harry leaves sw." is what comes from the mud. If it's "Harry leaves sw" then the regex for it should be ^(\w+) leaves (\w+)$


if you want to only autofollow a specific person, you could setup an alias like this

pattern: ^af (\w+)$

script:
autofollow = matches[2]


and then the trigger would be

pattern: ^(\w+) leaves (\w+)$
type: perl regex
script:
if matches[2] == autofollow then send(matches[3]) end

dss
Posts: 12
Joined: Tue Apr 13, 2010 4:17 pm

Re: Help with my first simple trigger?

Post by dss »

Oh my, yes - I see.

I've got more questions still. This is totally counterinuitive to me.

So for a basic autofollow:

If the mud sends "Harry leaves sw" (often in a string, not as the only statement like this for example "The wild antelope leaves southeast." So it's not always "Harry") then I can do the following:

1. Open the trigger panel
2. Create a new trigger
3. Name the trigger 'Autofollow'
4. In section one I enter "^(\w+) leaves (\w+)$" and from the drop down select perl regex
5. In the script area I enter "send(matches[3])"
6. Save and activate.

Now for all intents and purposes whenever "anyone" leave "anywhere" I will automatically follow them, provided the trigger is activated.

I have done this, and it is not working.

I have questions about what "send(matches[3])" means, where the match is, and how to determine that, but I think since I know nothing that this is an excellent place to begin.

What am I doing wrong?

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Help with my first simple trigger?

Post by demonnic »

well, the first thing to check is if the trigger is even firing. Easiest way to do that is to click the 'highlight' option and have it highlight. default is red on yellow, I believe, but since we're not doing it for aesthetics, leave it at that. But I believe the issue may in fact be that it's not just one word.


^(\w+) leaves (\w+)$ will captue "Harry leaves east" but will not capture "A deer leaves south" and it will only capture if it is the only thing on that line from the mud. So again, I think a selection of the kind of output you're looking at will help us greatly at this point, and perhaps a screenshot of the trigger as it is setup now.

as for matches... with

^(\w+) leaves (\w+)$

as the perl regex trigger pattern:

matches[1] will be equal to the entire match (the entire pattern, as it matched.. so if it was "Harry leaves west" then matches[1] will equal "Harry leaves west")
matches[2] will be "Harry"
matches[3] will be "west"

matches[1] will always be the entire match. In a perl regex trigger, the rest of the matches are populated when you use () to enclose a pattern (in the above example, \w+ which is like saying "One or more word characters")

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Help with my first simple trigger?

Post by tsuujin »

Here's a gimme:
Line: The wild antelope leaves southeast.
Regex: ^(.+) leaves (\w+)\.$
matches[2] = The wild antelope
matches[3] = southeast

to move only if the target is the person who moved:
[syntax=lua]
if matches[2]:find(target) then
send(matches[3])
end
[/syntax]

this is dependent on your target being properly capitalized. You can change to
[syntax=lua]
if matches[2]:lower():find(target:lower()) then
send(matches[3])
end
[/syntax]
if you want case insensitive matching.

dss
Posts: 12
Joined: Tue Apr 13, 2010 4:17 pm

Re: Help with my first simple trigger?

Post by dss »

Thank you both for your replies.

I am beginning to understand the basic ideas here. Thank you for this. However, the trigger is not actually working.
I am adding a screen shot of the trigger as it currently is, and hopefully I've just forgotten or missed something basic.

Image

What happens with the highlighting:
"The wild antelope" is highlighted
"leaves" is not highlighted
"west" is highlighted

Seems like it's grabbing everything correctly, but I still do not follow...
I am clearly missing something important here. I hope the screen shot helps.

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Re: Help with my first simple trigger?

Post by Jules »

That's due to how highlight trigger works. It's capturing all the "captured" values, and applying the highlight to them. If you want to highlight EVERYTHING, cut and paste this into the top of your code:
Code: [show] | [select all] lua
selectString(line)
fg("yellow")
bg("red")
resetFormat()

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Help with my first simple trigger?

Post by demonnic »

after the 'if' line, put

echo("The target matches")


if you get that echo, it means it's matching... if you do not, it means it is not the same, hence why you're not following.

Post Reply