TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Actions on dynamic lines matching a variable.

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
Feets



Joined: 03 Jan 2018
Posts: 8

PostPosted: Thu Jan 04, 2018 7:56 pm    Post subject: Actions on dynamic lines matching a variable. Reply with quote

Hi, I was working on triggers for a MUD, but ran into a problem with some lines that have no obvious pointers to match on.
The lines I receive I can match on names that I have saved in variables, since they always go in the beginning. The ones I send are a problem. What I'd want to do, is save all the names I need into something, have a trigger go through them all looking for a match in the line and then use whatever was matched to log the line in appropriately named directory and file.
Problem is, the names can be in any place of the sentence, for example if V is the name:

"You huggle V."
"You zip zip zippity zip around V."
"You damn V to an eternity of lag."
"You tug on your jacket, point at V the Monkey with both hands and say: Ayyyyyyyy..."

There is never a set number of words before or after the variable, and the name can be anything I enter.

So the idea is to go through the whole line, looking for that variable, and then log it to .../V/V-2018-01-05.txt. If the name was Name2, then .../Name2/Name2-2018-01-05.txt and so on.

I've found some answers in the forums on how to match something similar, but I couldn't make it use the match to log the line.

Is there any way to do what I want? Still new at this, trying to learn. Smile
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 346

PostPosted: Fri Jan 05, 2018 8:26 am    Post subject: Reply with quote

Try if this could work for you (the directories must exists, else no log is created):

Code:

#var namelist {name1|name2|name3|name4}

#action {%*{$namelist}%*} {
    #format {strdate} {./%2/%2-%t.txt} {%Y-%m-%d};
    #line log {$strdate} {%0}
} {10}


I also added a low priority to the action, to make it trigger only if the other action (with the names at the beginning) isn't triggered.
Back to top
View user's profile Send private message
Feets



Joined: 03 Jan 2018
Posts: 8

PostPosted: Fri Jan 05, 2018 11:17 am    Post subject: Reply with quote

Thank you! This works nicely, but for some reason, if I add another name to the list (not by editing the file), it doesn't capture that last name? It looks exactly the same, just with one more name, and if I add it by editing the file, it gets captured just fine.

Any idea why this happens?

The directory was created by another action, so it does exist.
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 346

PostPosted: Fri Jan 05, 2018 1:14 pm    Post subject: Reply with quote

What do you mean with "by editing the file" ?
I suppose you are speaking about the variable, right ?

That variable is NOT a tintin list, but actually contains a regexp, so it's important how the names are separated, and specifically with the "|" (pipe) character.

Maybe you should use a #LIST to manage the names (add,remove,etc...), and an #ALIAS to generate the actual regexp to be used.

If you don't know how, later I'll add that piece of code.
Back to top
View user's profile Send private message
Feets



Joined: 03 Jan 2018
Posts: 8

PostPosted: Fri Jan 05, 2018 1:47 pm    Post subject: Reply with quote

Well, if I manually add #var namelist {Name1|Name2|Name3|Name4} into the file from which it gets loaded, then it's all fine, but if I have only {Name1|Name2|Name3} and another action does #var namelist {$namelist|$namevar}, where $namevar is the new name (Name4), I get at least visually the same thing as the first example I mentioned, but the new name does not get captured.
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 346

PostPosted: Fri Jan 05, 2018 3:14 pm    Post subject: Reply with quote

Now I understand what you mean, in this case the problem is that the #action is already defined and doesn't use anymore the content of the variable, you should delete and declare again the #action after a change on the namelist.

Or, you can define the action to actively use the content of the variable at every check.

So I just added a "$" to the previous code, and just changing the content of the variable will do the trick:

Code:

#action {%*{$$namelist}%*} {
    #format {strdate} {./%2/%2-%t.txt} {%Y-%m-%d};
    #line log {$strdate} {%0}
} {10}
Back to top
View user's profile Send private message
Feets



Joined: 03 Jan 2018
Posts: 8

PostPosted: Fri Jan 05, 2018 4:43 pm    Post subject: Reply with quote

That solved it! Just one more (hopefully last) thing, could I make it match on the exact words? So it wouldn't match things like Name22.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Fri Jan 05, 2018 7:04 pm    Post subject: Reply with quote

That should be fairly easy, you could try:

Code:

#action {{.*\b}{$$namelist}{.*\b} {
    #format {strdate} {./%2/%2-%t.txt} {%Y-%m-%d};
    #line log {$strdate} {%0}
} {10}


or add spaces:

Code:

#action {%* {$$namelist} %*} {
    #format {strdate} {./%2/%2-%t.txt} {%Y-%m-%d};
    #line log {$strdate} {%0}
} {10}


Last edited by Scandum on Fri Jan 05, 2018 8:07 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Feets



Joined: 03 Jan 2018
Posts: 8

PostPosted: Fri Jan 05, 2018 7:55 pm    Post subject: Reply with quote

This seems to work only when I add those in the variable itself, like this: {\bName1\b|\bName2\b}, but that's fine, so I'll go with it. Smile

Thank you for the help, I'll see if I can make anything else break or just not work. Coffee
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Fri Jan 05, 2018 8:08 pm    Post subject: Reply with quote

Oh yeah, that's not working too well, this might:

Code:

#action {{.*\b}{$$namelist}{.*\b} {
    #format {strdate} {./%2/%2-%t.txt} {%Y-%m-%d};
    #line log {$strdate} {%0}
} {10}


Also found a major bug in the last release playing around with this trigger. Sad
Back to top
View user's profile Send private message Send e-mail
Feets



Joined: 03 Jan 2018
Posts: 8

PostPosted: Fri Jan 05, 2018 8:31 pm    Post subject: Reply with quote

This worked: {{.*\b}{$$namelist}{\b.*}} Smile

Thanks again, I thought it was a fairly tough one to match. Sad
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Sat Jan 06, 2018 1:29 am    Post subject: Reply with quote

Regular expressions get confusing real quick.

\b matches all word boundaries, spaces, commas, dots, start of line, end of line, etc.

I was overthinking it though, the following should work as well:

Code:

#action {%*\b{$$namelist}\b%*} {
Back to top
View user's profile Send private message Send e-mail
Feets



Joined: 03 Jan 2018
Posts: 8

PostPosted: Sat Jan 06, 2018 4:52 am    Post subject: Reply with quote

What if I told you that it doesn't work? Sad
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Sat Jan 06, 2018 10:11 am    Post subject: Reply with quote

It should work, might fail if you define the variable after the action however.
Back to top
View user's profile Send private message Send e-mail
Feets



Joined: 03 Jan 2018
Posts: 8

PostPosted: Sat Jan 06, 2018 11:19 am    Post subject: Reply with quote

You're right there, loading the file, which contains the variable, first seems to fix that issue.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Sun Jan 07, 2018 1:32 am    Post subject: Reply with quote

I wish there was a perfect way to handle it. If I change the behavior people who play MUDs that require $$ as input will start having problems.

Code:

#action {%*\b{$namelist}\b%*} {


That should do the trick if the variable is not defined. However, if you reload your files the behavior changes. And if you use #write there'll be problems as well.

It's one of the downsides of a dynamic scripting language, though handling variables in the trigger definition wasn't the brightest idea, in hindsight.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group