Capture using a variable

Post Reply
nesferatu
Posts: 6
Joined: Sat Apr 28, 2018 2:41 pm

Capture using a variable

Post by nesferatu »

I've successfully created a trigger to join a party.
The trigger captures the party name into a variable when joining.
In theory, this should allow me to then capture the 'party line' out to a separate window (as I currently do with tells and other lines), however I'm struggling to get the syntax right...

Mud output:
You have 60 seconds to type 'party join abc_123'. **Party Trigger activated**
party join abc_123
You join party 'abc_123'.
[Abc_123] Player1 waves hello
[Abc_123 Nesferatu] Hi everyone

Join Party Trigger (this works):
You have 60 seconds to type 'party join (\w+)' #Perl Regex
echo(" **Party Trigger activated**")
PartyName = matches[2]
send("party join "..PartyName)

Party Line Capture Trigger:
[..PartyName (\w+)]$ #(this is a Perl Regex statement)

selectString(line,1)
setBgColor(0,0,0);
copy()
appendBuffer("partycap"); #The name of my window to capture to.
deleteLine(); #gag the line from the main window

The problem I'm having is that it's grabbing output from everything and putting it into my 'party window'. I realise this is made hard because the party name is 1st-character upper-cased, but honestly I'm stumped.

Can anyone offer any advice please?

Thanks in advance..

nesferatu
Posts: 6
Joined: Sat Apr 28, 2018 2:41 pm

Re: Capture using a variable

Post by nesferatu »

I finally figured this out, once I realised Mudlet won't allow you to expand a variable in the trigger line..
Instead, I trigger on the '[' character and compare the output within a defined table, taking appropriate actions upon evaluation success..

Trigger regex: \[(\w*)

local lines_table = {"Warmage","Cleric","Druid","Ranger","Rogue","Fighter","Monk"}
if matches[2] == PlineName then
selectString(line,1)
setBgColor(0,0,0);
copy()
appendBuffer("partycap");
deleteLine();
elseif table.contains(lines_table, matches[2]) then
selectString(line,1)
setBgColor(0,0,0);
copy()
appendBuffer("chancap");
deleteLine();
end

Kasa
Posts: 2
Joined: Sun Apr 29, 2018 11:45 pm

Re: Capture using a variable

Post by Kasa »

I believe you would also be able to use the lua function trigger type, and do

Code: Select all

return string.find(line,  "%[PartyName%]")
Or along those lines.

Kasa
Posts: 2
Joined: Sun Apr 29, 2018 11:45 pm

Re: Capture using a variable

Post by Kasa »

Code: Select all

return string.find(line, "%["..PartyName.."%]")
would be another solution, I believe.

Post Reply