Not understanding something Fundamental about multi-line triggers.

Post Reply
Eikel
Posts: 2
Joined: Mon Jul 26, 2021 6:54 am

Not understanding something Fundamental about multi-line triggers.

Post by Eikel »

Hi all,

Apologies if this question seems self-explanatory, I'm struggling to grasp how multi-line triggers work.

My objective is to parse a number of lines subsequent to the line that fires the trigger, sounds simple enough?
Here's what the output from my MUD looks like (I typed "scan" to generate this):

Code: Select all

< 1353h/1353H 209v/213V Pos: standing >
scan
<> 

You quickly scan the area.
An elite Tharnadian warrior who is rather far off to your east.
An elite Tharnadian warrior who is rather far off to your east.
A noble white steed who is rather far off to your east.
Meldar the Tharnadian Marshall who is rather far off to your east.
A Town Guardian who is close by to your west.
A Town Guardian who is close by to your west.
An elite guard who is not far off to your west.
A religious zealot who is a brief walk away to your west.
A militia guard who is in the distance to your west.
A militia guard who is in the distance to your west.

< 1353h/1353H 211v/213V Pos: standing >
<> 
I'm currently matching on the "You quickly scan the area." line, and I want to parse the subsequent text until I reach the "<" character displayed in the prompt, my trigger is enabled for "AND /multi-line (delta)".

My trigger code currently looks like this:

Code: Select all

found = false
Ogres = 0
Drows = 0
Trolls = 0
ThriKreens = 0
Orcs = 0
Duergars = 0
Goblins = 0
Kobolds = 0

while not string.find(line, "<") do
  moveCursor(0,getLineNumber()+1)
  if string.find(line, "Ogre") then
    Ogres = Ogres + 1
    found = true
  elseif string.find(line, "Drow") then
    Drows = Drows + 1
    found = true
  elseif string.find(line, "Orc") then
    Orcs = Orcs + 1
    found = true
  elseif string.find(line, "Troll") then
    Trolls = Trolls + 1
    found = true
  elseif string.find(line, "Thri-Kreen") then
    ThriKreens = ThriKreens + 1
    found = true
  elseif string.find(line, "Duergar") then
    Duergars = Duergars + 1
    found = true
  elseif string.find(line, "Kobold") then
    Kobolds = Kobolds + 1
    found = true
  elseif string.find(line, "Kobold") then
    Goblins = Goblins + 1
    found = true
  end
end

if (found == true) then
  outString = "gcc -<Eikel>- SCAN: "
  send(outString)
end

return 0
Unfortunately all this currently does is cause mudlet to hang (infinite loop I'd guess) and then eventually crash.
I've tried adding echo("Debug: ") statements to show me where the problem is but they never get outputted, the program hangs, and then crashes.

Any help is much appreciated!

--Eikel.

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

Re: Not understanding something Fundamental about multi-line triggers.

Post by demonnic »

This is actually a good candidate for using a trigger chain, the multi-line AND triggers are for when you have multiple conditions you know must be met before anything runs, whereas trigger chains are for when you want some set of triggers to only be evaluated after another one has matched.

I have attached a trigger which I think will do what you want, or at least can be adjusted until it does. First you trigger off of "You quickly scan the area." and set the fire length to 1. In that trigger you handle the initialization stuff (resetting things to 0, etc)

Then a perl regex trigger matching on .* with a slightly modified version of the rest of your code in it. Namely, rather than placing everything into a dangerous, potentially infinite loop I just have the check for "<" bail out of the trigger without setting the fire length any longer.

So the workflow then is->
you quickly scan the area matches
next line after that will be evaluated for the mobs you're looking for, and will cause it to look for one more line
unless it has a "<" in it, in which case it returns from the trigger without doing anything, including extending the trigger time, so the chain closes.

For more information: https://wiki.mudlet.org/w/Manual:Trigge ... ter_Chains
Attachments
scanning.xml
(2.63 KiB) Downloaded 11 times

Eikel
Posts: 2
Joined: Mon Jul 26, 2021 6:54 am

Re: Not understanding something Fundamental about multi-line triggers.

Post by Eikel »

Thank you so much! This is fantastic, exactly what I was after!
You're a Legend!

--Eikel

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

Re: Not understanding something Fundamental about multi-line triggers.

Post by demonnic »

I'm glad I could help out =)

Post Reply