Help with my first simple trigger?

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

Re: Help with my first simple trigger?

Post by dss »

I'm totally confused.

Code: Select all

if matches[2]:
find(target)
then 
send(matches[3])
end
This highlights both the Object leaving, and the direction it goes, but nothing is sent to the mud and I do not follow.

match [2] is the Object leaving
match [3] is the direction
send(matches[3]) is the command which should tell the mud that I want to move in that direction

Is there something I'm missing? Why wouldn't it go in that direction?

using this:

Code: Select all

if matches[2]:
find(target)
then 
send(matches[3])
echo("The target matches")
end
Doesn't echo anything at all. Thus, I am to assume that the target does not match, right?
But it highlights, and so I have to assume that it does match something and I'm just not telling it what to do correctly?

I've spent the morning reading the manual, and it's got my brain in a pile. It's quite complex (from my inexperienced pov) and I simply don't understand.

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

Re: Help with my first simple trigger?

Post by demonnic »

if matches[2]:find(target) then
echo("IT worked!\n")
send(matches[3])
else
echo("The target didn't match")
end

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

Re: Help with my first simple trigger?

Post by dss »

demonnic wrote:if matches[2]:find(target) then
echo("IT worked!\n")
send(matches[3])
else
echo("The target didn't match")
end
This is the script I copied and pasted into the script area.

Still, Mudlet highlights "The sand crab leaves east.

But I do not follow, and the send messages "IT worked!" and "The target didn't match" do not send. Not as a spoken string, nor as an error.

Would the particular settings or type of mud this is have an affect on the scripting? If it were sending to the mud I would at least get a "What?" from it. That's the response I get when I just type it into the text input area.

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

Re: Help with my first simple trigger?

Post by demonnic »

and are you getting any errors in the error display or debug console?

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

Re: Help with my first simple trigger?

Post by dss »

no errors in the mud or when saving the trigger.

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

Re: Help with my first simple trigger?

Post by demonnic »

yes, but when you click on error, does anything come up when the trigger actually runs?

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

Re: Help with my first simple trigger?

Post by dss »

Code: Select all

new line arrived: The small rabbit leaves south.
Trigger name=auto follow(^(.+) leaves (\w+).\$) matched.
capture group #1 = <The small rabbit leaves south.>
capture group #2 = <The small rabbit>
capture group #3 = <south>

selectSection(0,16): line under current cursor: The small rabbit leaves south.
P_begin(0/1383), P_end(16/1383) selectedText = The small rabbit

selectSection(24,5): line under current cursor: The small rabbit leaves south.
P_begin(24/1383), P_end(29/1383) selectedText = south

LUA: ERROR running script auto follow (Trigger10) ERROR:[string "function Trigger10()..."]
bad argument #1 'find' (string expected, got nil)
This is what it says in the central debug console.

In this mud 's' works as well as 'south' which for a second I thought might be the trouble, but it's something else well over my head here.

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

Re: Help with my first simple trigger?

Post by dss »

I got it working from examining the error. What it looks like to me is the portion of the script:

Code: Select all

:find(target)
was causing the error and so it wasn't working.

Since I don't understand what find(target) is supposed to mean or do, I don't know what I'm missing here, but after removing this from the script so it now reads:

Code: Select all

if matches[2] then
send(matches[3])
else
end
I am successfully following the rabbit around the field. It works!

So to extrapolate based on your work, and attempting to make use of your kind help, I thought I would make a second trigger which allowed me to examine anything which "arrives".

Here's what I wrote:

Code: Select all

^(.+) arrives\.$
perl regex

Code: Select all

if matches[2] then
echo("examine it")
end
What I assumed was that based upon the above success, that it would be quite simple to write little snippets of code to do things like this. Thus, whenever anything "arrives" I would "examine it" and get a closer look at everything all the time, and have it for later if I needed it.

Sadly, I was wrong, and this doesn't work either.

I guess I have a whole lot more to learn. Is there an easier, or rather more simplified guide to LUA and how triggers, filters, and alliases are written for mudlet? I think I need the idiot's guide, but I really want to understand this.

Yugosan
Posts: 4
Joined: Wed Mar 31, 2010 11:33 am

Re: Help with my first simple trigger?

Post by Yugosan »

I think the problem atm is that the manual is fairly technical for people with no prio programming/scripting experince and as such makes it hard for them to use mudlet atm, but im sure with time a more "newbie" friendly version will come out.

Regarding your attempt to make another trigger seems like a great idea to build on previous experience ;)

building on the previous trigger using the rabbit as an example i would guess (and it is only a guess since i am abit of a newbie myself at this) that it would look something like this:

The small rabbit arrives. <--- the line the mud sends when the rabbit arrives into the room your in.

^(.+) arrives.\$ <--- this seems right to me since its the same as "^(.+) leaves (\w+).\$" but without the second match and "leaves" changed with "arrives".

Code: Select all

if matches[2] then
echo("examine it")
end
now this is the code piece that is abit wierd if you ask me, because what you are doing here is saying:

If "something" then i shall echo examine it to the screen. now im asking myself: if "something"? why would i have this in the trigger? (now i think know why but i will come to that in abit)

what you need is fairly simply, since you want to echo"examine it" everytimes something arrives, you simply have a trigger with the code:

Code: Select all

echo("examine it")
insted of

Code: Select all

if matches[2] then
echo("examine it")
end
now to the reason i think you are using if....

In the other trigger the people helping have being using a variable called "target" that was what the :find(target) was for. Im also guessing that you dont have the alias mention earlier and therefor it cannot find the "target".
the problem with your first trigger now is:

Code: Select all

A room [exits: north, south, east, west]
tiny spider
small rabbit

hp: over9000!>
Lets say you wanna follow the rabbit, but the spider moves first sending the line:

tiny spider leaves south.

Your trigger would fire off and you will follow the spider insted of the rabbit.
thats no good. So what can we do to make sure you follow the one that you want too. Here is it the alias comes into play.
You type: af rabbit
now the alias tells mudlet to put the rabbit into a variable called target.
now when the spider leaves the trigger fires off but this time you have the :find(target) in your trigger and you have set the target to rabbit, so it looks for who left? tiny spider, is that the same name as the one in the variable "target"....no, ok then i will not follow it. And if the rabbit leaves then it will say, yes its the same name as the variable "target" so i will follow it.

so here is what you need for the triggers:
first you make an alias:

Code: Select all

pattern: ^af (\w+)$

script:
target = matches[2]
then you make the trigger:

Code: Select all

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

script:
if matches[2]:find(target) then
send(matches[3])
end
now each time you wanna follow a specific monster or player you type: af nameofmonster (example: af rabbit), however if the rabbit is called: a tiny rabbit and the mud send the line: a tiny rabbit leaves south, then you wanna change things around abit, so insted of the (\w+) in the alias you put in (.+) this way you can put more than 1 word into the variable target.

for the second trigger:

Code: Select all

pattern: ^(.+) arrives.$

script:
echo("examine it")

or if your mud have a command to examine the monsters:
send("examine ".. matches[2])
that will send the command: examine whoeverarrives to the mud
i hope this make any sense, but also i hope this shows what is required in the "newbie" manual the details you need to show and how much you need to make stuff simple (not that i think what i just wrote is simple :D )

Yugosan

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

Re: Help with my first simple trigger?

Post by dss »

Thank you. I am really beginning to understand now.

I will test the improved autofollow targeting, and the matching approach to examine anything arriving and reply here with results.

What a deep and wonderful application. Thank you for helping me get into it.

Post Reply