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

How to recognize {} (braces)?

 
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 01, 2016 8:38 pm    Post subject: How to recognize {} (braces)? Reply with quote

I am trying to recognize braces (i.e. {}) in MUD output line, and it's not working.

This TinTin++ forum post discusses a very similar issue.

I am trying to detect braces in the following MUD output line:
Quote:
A peasant {2}.


Code:
#line substitute escapes #regex {A peasant \x7B2\x7D} {^%+ {\x7B.+?\x7D}$} {#echo {&1}} {#echo {no match!}}

The above TinTin++ command successfully displays 'A peasant' when typed within a terminal as a live command, but returns 'no match!' when executed in a script file.


Code:
#line substitute escapes #var {brace} {\x7B}
#line substitute escapes #format {brace} {%s} {\x7B}


Both of the above commands return the following error:
Quote:
#Unmatched braces error!



What's the way to recognize braces in TinTin++ script?


I'm using TinTin++ 2.01.1 compiled on Cygwin.
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Wed Jun 01, 2016 9:40 pm    Post subject: Reply with quote

What do you mean by "detect" ?
I can't understand what is your purpose, you just want to change them or just get what they contains, remove them or something else ?

Because the solution could be different in any of those cases

as an example, this is working to get the number:
Code:

#action {%+ \x7B%+\x7D} {#echo {%2};}
#OK. {%+ \x7B%+\x7D} NOW TRIGGERS {#echo {%2};} @ {5}.
#showme A peasant {2}.
2
A peasant {2}.


this is working to substitute them with a "-"
Code:

#substitute {%+ \x7B%+\x7D} {%1 -%2-}
#OK. {%+ \x7B%+\x7D} IS NOW SUBSTITUTED AS {%1 -%2-} @ {5}.
#showme A peasant {2}.
A peasant -2-.


Also, does that line contains colors or maybe some extra invisible informations when it comes from the MUD ?
You should do a RAW log of the MUD output to be certain of that
Code:

#config log raw
#log append mylog.txt

#nop Play a little in the MUD and then

#log off
Back to top
View user's profile Send private message
TTPPfan



Joined: 05 May 2016
Posts: 11

PostPosted: Wed Jun 01, 2016 10:00 pm    Post subject: Reply with quote

When the following MUD output line

Quote:
A peasant {2}.


is received in the following TinTin++ command

Code:
#event {RECEIVED LINE}


" {2}" should be removed and only "A peasant" should be stored in a TinTin++ variable.

I can't get #regex command to do that.

How can that be done?


No invisible information in the line. It's purely detecting braces in #regexp issue. Try the following commands. They all fail to detect a match.

Code:
#regex {A peasant \x7B2\x7D} {^%+ \x7B%d\x7D$} {#echo {match!}} {#echo {no match!}}
#regex {\x7B} {\x7B} {#echo {match!}} {#echo {no match!}}
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Wed Jun 01, 2016 11:01 pm    Post subject: Reply with quote

Played a little with double brackets, but I'm not sure if it's still interpreting the codes as brackets

Code:

#regex {{\x7B}} {\x7B} {#echo {match!}} {#echo {no match!}}
match!


mmm, it seems somehow to recognize it... maybe it is not echoed well, but seems like that the double brackets in the regex are working
Code:

#regex {{\x7B}} {%+} {#echo {match! "&1"}} {#echo {no match!}}
match! "{{}"


Last edited by PowerGod on Wed Jun 01, 2016 11:07 pm; edited 1 time in total
Back to top
View user's profile Send private message
TTPPfan



Joined: 05 May 2016
Posts: 11

PostPosted: Wed Jun 01, 2016 11:03 pm    Post subject: An update Reply with quote

For the following MUD output
Quote:
A peasant {2}.


Code:
#event {RECEIVED LINE}
{
   #line substitute escapes #regex {%1} {^%+ {\x7B.+?\x7D}.$} {#echo {&1}}
}

finds the match and displays "A peasant".

However, all of the following tt++ commands fail to detect any match
Code:
#event {RECEIVED LINE}
{
   #line substitute escapes #regex {%1} {^%+ {\x7B}%d{\x7D}.$} {#echo {&1  &3}}
}

#event {RECEIVED LINE}
{
   #line substitute escapes #regex {%1} {^%+ {\x7B}%+{\x7D}.$} {#echo {&1  &3}}
}

#event {RECEIVED LINE}
{
   #line substitute escapes #regex {%1} {^%+ {\x7B}%*{\x7D}.$} {#echo {&1  &3}}
}



How can the #regexp command be updated, so that what's in the braces ('2', in this case) can be stored in a tt++ variable as well, not just what's before the braces?
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Mon Jun 06, 2016 10:15 am    Post subject: Reply with quote

I did something, using an action just because events works only on active sessions, but using #scan to read the line as it was received from a mud

Code:

#action {%*} {#line substitute escapes #regex {%1} {^%+ \x7B{[0-9]\+}\x7D.$} {#var {temp} {&2}; #echo {-&1- -&2- $temp}}}


this is the debug result, it will trigger and gets the number too, but still it keeps the {} around... I tried also to put the regexp result to a variable, but because of the brackets it initialize it wrong...

Code:

#scan peasant.txt
[02] scan peasant.txt
#DEBUG ACTION {%*}
[02] line substitute escapes #regex {A peasant \x7B2\x7D.} {^%+ \x7B{[0-9]\+}\x7D.$} {#var {temp} {&2}; #echo {-&1- -&2- $temp}}
[15] regexp {A peasant {2}.} {^%+ {{[0-9]+}}.$}
[02] variable {temp} {{2}}
#OK. VARIABLE {temp} HAS BEEN SET TO {{2}{}}.
[02] echo {-A peasant- -{2}- $temp}
-A peasant- -{2}- {2}{}
A peasant {2}.
#OK. FILE SCANNED.


this part is the one that show the result, -&1- -&2- and the content of the variable temp

Code:

-A peasant- -{2}- {2}{}


I'll continue to play with this when I'll find the time... there must be a way
Back to top
View user's profile Send private message
TTPPfan



Joined: 05 May 2016
Posts: 11

PostPosted: Mon Jun 06, 2016 10:41 am    Post subject: Reply with quote

Thanks for the effort! I really appreciate it!
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Mon Jun 06, 2016 11:24 am    Post subject: Reply with quote

This seems working... it puts the line in a variable, removes from there the brackets and then does the regexp on the variable itself

Code:

#ACTION {%*} {
    #line substitute escapes #var temp {%1};
    #REPLACE {temp} {\x7b} {};
    #REPLACE {temp} {\x7d} {};
    #line substitute escapes #regex {$temp} {^%+ {[0-9]\+}.$} {
        #var {temp} {&2};
        #echo {-&1- -&2- $temp}
    }
}


the debug result:
Code:

#scan peasant.txt
[02] scan peasant.txt
#DEBUG ACTION {%*}
[02] line substitute escapes #var temp {A peasant \x7B2\x7D.}
[02] variable temp {A peasant {2}.}
#OK. VARIABLE {temp} HAS BEEN SET TO {A peasant {2}.}.
[02] replace {temp} {\x7b} {}
[02] replace {temp} {\x7d} {}
[02] line substitute escapes #regex {$temp} {^%+ {[0-9]\+}.$} {#var {temp} {&2}; #echo {-&1- -&2- $temp}}
[15] regexp {$temp} {^%+ {[0-9]+}.$}
[02] variable {temp} {2}
#OK. VARIABLE {temp} HAS BEEN SET TO {2}.
[02] echo {-A peasant- -2- $temp}
-A peasant- -2- 2
A peasant {2}.
#OK. FILE SCANNED.


the resulting line seems correct without the brackets
Code:

-A peasant- -2- 2
Back to top
View user's profile Send private message
TTPPfan



Joined: 05 May 2016
Posts: 11

PostPosted: Wed Jun 08, 2016 1:56 pm    Post subject: Reply with quote

Such extra processing for a regexp operation that should be simple in the first place.

Nonetheless, removing the braces ({}) with #replace seems to be the only viable way to do it for now.

Thanks a lot for all the efforts and the great solution!
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Thu Aug 25, 2016 7:25 pm    Post subject: Reply with quote

Can try:

#regex {A peasant {2}} {%+ \{%2\}} {#showme -&2-}

Or alternatively:

#regex {A peasant {2}} {%+ \x7b%2\x7d} {#showme -&2-}


It's not something TinTin++ handles well unfortunately.

I think internally { might be converted to \x7b when captured by an action to make life easier (and for security reasons). So in that case you would need #line substitute escapes to convert that \x7b to a {, so you would use:

#line substitute escapes #regex {%0} {%+ \\{%2\\}} {#showme -&2-}

I know, that's a real mind bender.
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