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

Catching a complex MUD output with color codes in #action

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



Joined: 05 May 2016
Posts: 11

PostPosted: Wed Jun 08, 2016 2:25 pm    Post subject: Catching a complex MUD output with color codes in #action Reply with quote

I am trying to capture the following MUD output (logged in raw format with manually replaced 'ESC' character for visibility) in an #action command.

Code:
ESC[0mStrength       :  16 (ESC[36;1m 16ESC[0m)  ESC[32;1m        2,446ESC[0m               6,577ESC[0m


When displayed in terminal, the above MUD output looks like the following:
Code:
Strength       :  16 ( 16)          2,446               6,577

The 16 in the parentheses is in light blue, and 2,446 is in bright green. The rest are in grey.


I need to capture the numbers separately and store each in a variable. (i.e. 16, 16 in the parentheses, 2,446, and 6,577, without any leading or trailing spaces.


I have tried the following #action command to capture the numbers separately.

Code:

#action {Strength%s:%s%3%s(%s%6)%s%8%s%10} {#echo {strength%1:%2|%3|%4|%5|%6|%7|%8|%9|%10};#echo {%0}}


The above #action command, when executed, #echo's the following:
Code:

strength       :|  16| || 16||||          2,446               6,577
Strength       :  16 ( 16)          2,446               6,577

which indicates that %s do not work at all after the semicolon.


The following #action command
Code:
#action {Strength%s:%s%S%s(%s%S)%s%S%s%S} {#echo {strength%1:%2|%3|%4|%5|%6|%7|%8|%9|%10};#echo {%0}}

#echo's the following when executed:
Code:
strength       :  |16| | |16||||
Strength       :  16 ( 16)

It doesn't capture anything after the closing parenthesis.


How can I make the #action command catch all four numbers separately?

I'm using TinTin++ 2.01.1 compiled on Cygwin.


Last edited by TTPPfan on Thu Jun 09, 2016 6:45 pm; edited 1 time in total
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Thu Jun 09, 2016 3:45 pm    Post subject: Reply with quote

It is better not to replace ESC characters when you post a log, this way it can be just copy/pasted to try it fron tintin.

Can that string contains more than 4 numbers ? Or maybe them can change disposition in some circumstances ?
I ask that because I see that you used 8 separators to get those numbers, were you just trying to see what was grabbed from the pattern ?

Your problem are the colors, have a read at this discussion to understand better how them works: http://tintin.sourceforge.net/board/viewtopic.php?p=9461#9461

Short explanation: colors are part of the string, so you have to consider their disposition when writing the action.

Also, dealing with colors is a mess... REALLY !!

anyway, have a look at what I did here:
Code:

#action {Strength%s:%s{[0-9]+}%s({\s*}%+)%s{[0-9,]+}%s{[0-9,]+}} {#echo {%3|%6|%8|%10}};


it echoes this:
Code:

16|16|2,446|6,577


I used both regular expressions and tintin syntax, but the only way to be sure when you need to use one or another is to see the result.

For example, in this case, if I change this "({\s*}%+)" to this "(%s%+)" it doesn't remove the space... (before the space there's a color)

Also, you may find useful the #LINE STRIP command to remove color codes from lines.
Back to top
View user's profile Send private message
TTPPfan



Joined: 05 May 2016
Posts: 11

PostPosted: Thu Jun 09, 2016 6:39 pm    Post subject: Reply with quote

The original MUD output (without ESC replacements):
Code:
Strength       :  16 ( 16)          2,446               6,577



I have included eight separators, in order to see what the %s's catch. The MUD output line contains only four numbers.


#help action displays the following info, which makes it sound like color codes in the MUD outputs don't have to be an issue and will be ignored if you simply don't start the #action {search string} with ~.
Quote:
If the search string starts with ~, color codes must be matched, which you can see by enabling: #config {convert meta} on.

Apparently, color codes in the MUD outputs are NOT ignored in #action search strings.


The code you gave doesn't catch the MUD output (as expected), since it is not designed to handle the color codes:
Code:

#action {Strength%s:%s{[0-9]+}%s({\s*}%+)%s{[0-9,]+}%s{[0-9,]+}} {#echo {%3|%6|%8|%10}}
#showme {Strength       :  16 ( 16)          2,446               6,577}

produces no output.


Using your hints, I've tried the following code:
Code:

#action {Strength%s:%s%1} {#line {strip} {#regexp {%1} {%s%S%s(%s%S)%s%S%s%S} {#echo {&2|&5|&7|&9}}}}
#showme {Strength       :  16 ( 16)          2,446               6,577}

but it caught only the first two numbers and failed to catch the last two numbers as in the following:
Code:
16|16||


So, I have updated your code to the following, and now it catches all of the four numbers!
Code:

#action {Strength%s:%s%1} {#line {strip} {#regexp {%1} {%s{[0-9,]+}%s(%s{[0-9,]+})%s{[0-9,]+}%s{[0-9,]+}} {#echo {&2|&5|&7|&9}}}}
#showme {Strength       :  16 ( 16)          2,446               6,577}

Code:
16|16|2,446|6,577



Again, thanks much for all the help!
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Fri Jun 10, 2016 2:29 am    Post subject: Reply with quote

Just tried my previous action, and it still works, but I see what you did there, you can't use #showme with a raw mud line because it doesn't understand the escapes, you should do one of these things:

1) paste the raw line directly on tintin, so it will convert the escapes, and then use the result as argument for tintin functions, for example this is how the #showme string becomes (and the result of my previous action):

Code:

#action {Strength%s:%s{[0-9]+}%s({\s*}%+)%s{[0-9,]+}%s{[0-9,]+}} {#echo {%3|%6|%8|%10}};
#OK. {Strength%s:%s{[0-9]+}%s({\s*}%+)%s{[0-9,]+}%s{[0-9,]+}} NOW TRIGGERS {#echo {%3|%6|%8|%10}} @ {5}.
#showme {\e[0mStrength       :  16 (\e[36;1m 16\e[0m)  \e[32;1m        2,446\e[0m               6,577\e[0m}
16|16|2,446|6,577
Strength       :  16 ( 16)          2,446               6,577


2) put the raw line (with original escapes) in a text file, and then read it from tintin using #SCAN (and then press page-up and page-down to see the result), also here the result of my previous action:

Code:

#action {Strength%s:%s{[0-9]+}%s({\s*}%+)%s{[0-9,]+}%s{[0-9,]+}} {#echo {%3|%6|%8|%10}};
#OK. {Strength%s:%s{[0-9]+}%s({\s*}%+)%s{[0-9,]+}%s{[0-9,]+}} NOW TRIGGERS {#echo {%3|%6|%8|%10}} @ {5}.
#scan string.tt
16|16|2,446|6,577
Strength       :  16 ( 16)          2,446               6,577

#OK. FILE SCANNED.


I used that mess with tintin syntax and regexp just because is a trick to ignore colors.
Back to top
View user's profile Send private message
TTPPfan



Joined: 05 May 2016
Posts: 11

PostPosted: Fri Jun 10, 2016 5:30 am    Post subject: Reply with quote

The first method was what I used the last time I tried it.

I tried your #action command again, and it works on my TinTin++ as well. I must've made a mistake last time.
Back to top
View user's profile Send private message
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