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

odd matching

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



Joined: 29 Jan 2012
Posts: 24

PostPosted: Wed Oct 08, 2014 11:42 am    Post subject: odd matching Reply with quote

I think this should match on all on bli,bla,blo spam and not only on bla, shouldn't it?
Code:

#act {^[%*]$} {#show @reply{%1}}
#OK. {^[%*]$} NOW TRIGGERS {#show @reply{%1}} @ {5}.
#fun reply {#var result {%1}; #regex {${result}} {{{bli|bla|blo} spam|egg|ham}} {#var result YES;} {#var result NO;}}
#OK. FUNCTION {reply} HAS BEEN SET TO {#var result {%1}; #regex {${result}} {{{bli|bla|blo} spam|egg|ham}} {#var result
YES;} {#var result NO;}}.


This is odd:
Code:

#show [bli spam]
NO
[bli spam]
#show [bla spam]
YES
[bla spam]
#show [blo spam]
NO
[blo spam]


Though those are okay:
Code:

#show [bli egg]
YES
[bli egg]
#show [bla egg]
YES
[bla egg]
#show [blo egg]
YES
[blo egg]
#show [bli ham]
YES
[bli ham]
#show [bla ham]
YES
[bla ham]
#show [blo ham]
YES
[blo ham]


Ammendment:
Changing the regex to:
Code:

#fun reply {#var result {%1}; #regex {${result}} {{{dummy|bli|bla|blo|dummy} spam|egg|ham}} {#var result YES;} {#var result NO;}}

matches like expected:

Code:

#show [bli spam]
YES
[bli spam]
#show [bla spam]
YES
[bla spam]
#show [blo spam]
YES
[blo spam]
Back to top
View user's profile Send private message
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Wed Oct 08, 2014 12:37 pm    Post subject: Reply with quote

DANGER WILL ROBINSON...! DANGER...! Nope
Quote:
Code:
#act {^[%*]$} {#show @reply{%1}}

Take care with that, that #ACTION will fire on EVERY line and certainly on older TinTin++ (can't speak for the last couple of versions) that INCLUDES lines that the #SHOWME puts out which will then go through your reply function a second time and if that produces any output it will trigger the #ACTION again and so on until it crashes...

Also - as TinTin++ only runs one #ACTION using the lowest numbered priority on a scale of 1-9 (default of 5) the only way to programmatically stop such "grab-all" #ACTIONS is for a higher priority #ACTION (lower number) to trip and remove it. A wild-card action such as this IS a valid technique to grab multiple lines but you need to be very sure that the thing to stop it (a variable updated by the action itself that counts the number of time the action has fired and removes the action itself if a limit has been exceeded is the other way) is in-place BEFORE this action gets created.

If you ever need an #action to put out text that might trigger itself you should use #ECHO instead, alternatively using #SHOWME is a way to to trigger another #ACTION to get around the one #ACTION per line of text limit.
Back to top
View user's profile Send private message
moire



Joined: 29 Jan 2012
Posts: 24

PostPosted: Wed Oct 08, 2014 12:51 pm    Post subject: Reply with quote

Slysven wrote:
Take care with that, that #ACTION will fire on EVERY line

No, here it does not. It only matches if the line starts with "[" and ends with "]" and passes the text inbetween to the function. This is lazy match, not a pcre, isn't it?
Back to top
View user's profile Send private message
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Thu Oct 09, 2014 8:43 am    Post subject: Reply with quote

Um, er, probably, Embarassed
In mitigation, I may have taken them as a range of characters from a different style of expression. I was wrong this time - but for anyone else reading this, the warning still stands about wild-card #ACTIONs that will happily eat their own output...! Confused
Back to top
View user's profile Send private message
moire



Joined: 29 Jan 2012
Posts: 24

PostPosted: Wed Oct 15, 2014 12:40 pm    Post subject: Re: odd matching Reply with quote

moire wrote:
I think this should match on all on bli,bla,blo spam and not only on bla, shouldn't it?
Ammendment:
Changing the regex to:
Code:

#fun reply {#var result {%1}; #regex {${result}} {{{dummy|bli|bla|blo|dummy} spam|egg|ham}} {#var result YES;} {#var result NO;}}

matches like expected:


And it works when I use parentheses (which would be transcribed to curly braces according to the documentation) inside the curly braces like this:
Code:

#fun reply {#var result {%1}; #regex {${result}} {{(bli|bla|blo) spam|egg|ham}} {#var result YES;} {#var result NO;}}


HTH
Back to top
View user's profile Send private message
Slysven



Joined: 10 Apr 2011
Posts: 365
Location: As "Jomin al'Bara" in WoTMUD or Wiltshire, UK

PostPosted: Thu Oct 16, 2014 7:40 pm    Post subject: Reply with quote

Can I just check, are you seeking a match on:
any one of : "bli", "bla" or "blo"
followed by " " (a space)
followed by any one of:"spam", "egg" or "ham"

If THAT is the case think I think your "{" "}" are not right:
Original:
Code:
#fun reply {#var result {%1}; #regex {${result}} {{{bli|bla|blo} spam|egg|ham}} {#var result YES;} {#var result NO;}}

I think it should be:
Code:
#fun reply {#var value {%1}; #regex {${value}} {{{bli|bla|blo} {spam|egg|ham}} {#return YES} {#return NO}}
The ';' are only needed to separate multiple commands within the same "{ ... code .... }" block and those last two #var assignments are the only commands in their blocks. Also "result" is a slightly special value used to return results from a #function, it may not be a good idea to assign it a value anywhere else within a #function.

Actually with your original expression it ought to match on:
"bli spam", "bla spam", "blo spam", "egg", "ham" but it seems to also respond with a "YES" for "bla" on it's own... Confused
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