Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Dwoggurd
Wanderer


Joined: 29 Jan 2008
Posts: 63

PostPosted: Fri Jun 13, 2008 12:04 am   

[2.27] #SUB and ANSI colored triggers wierdness
 
I run into this problem when I tried to dig this topic: ANSI colors
I decided to create a separate thread because I'm not sure what is going on.

Since a prompt from my mud is not terminated by "new line" the incoming text is often joined the prompt. I'm trying to make a trigger that splits it into two pieces, the prompt and the other text.
It looks like #SAY output falls into this category as well so it is joined the prompt line.
I'm trying to preserve text colors (and prompt colors) and I also need to process additinal text after a prompt as usual mud output, so I use #SHOW to mimic it.

Here is the regex trigger I'm playing with:
Code:
<trigger priority="101" case="true" ansi="true" trigontrig="false" regex="true" id="720">
  <pattern>(^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*)</pattern>
  <value>#IF (%3 != %null)
{
  #SUB {%1}
  #SHOW %3
}</value>
</trigger>


Notice, though this trigger is supposed to catch prompts I have an option trigger on newline = on because I want it to fire only when a trigger is followed by random text in the same line.
I tried different options for this trigger to make it work and below I list them with results from the script debugger window:

I do press ENTER to invoke a mud prompt and then I execute #SAY ===.

1) ansi color = off, trigger on trigger = on
visible result:
<100%hp 100%m 100%mv 1750tnl (50.00%)>
===
It works as expected but preserves no colors which I don't like.

debugger spam:
Code:
0.0020 | c      test |  exec : #SAY ===
0.0016 | a      test |<100%hp 100%m 100%mv 1750tnl (50.00%)> ===
0.0016 | f      test |  Pattern: (^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*) : (%1="<100%hp 100%m 100%mv 1750tnl (50.00%)> ", %2="", %3="===")
0.0014 | c      test |  exec : Pattern "(^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*)" : #IF (...
0.0019 | a      test |===
0.0031 | g      test ====


2) ansi color = on, trigger on trigger = off
visible result:
<100%hp 100%m 100%mv 1750tnl (50.00%)> ===
For some reason, the prompt line is not split, however colors are preserved.

debugger:
Code:
c      test |  exec : #say ===
a      test |<100%hp 100%m 100%mv 1750tnl (50.00%)> ===
f      test |  Pattern: (^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*) : (%1="<100%hp 100%m 100%mv 1750tnl (50.00%)> ", %2="", %3="===")
c      test |  exec : Pattern "(^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*)" : #IF (...
a      test |<100%hp 100%m 100%mv 1750tnl (50.00%)> ===
g      test =<100%hp 100%m 100%mv 1750tnl (50.00%)> ===


3) ansi color = on, trigger on trigger = on
trigger falls into a loop

debugger:
Code:
c      test |  exec : #say ===
a      test |<100%hp 100%m 100%mv 1750tnl (50.00%)> ===
f      test |  Pattern: (^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*) : (%1="<100%hp 100%m 100%mv 1750tnl (50.00%)> ", %2="", %3="===")
c      test |  exec : Pattern "(^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*)" : #IF (...
a      test |<100%hp 100%m 100%mv 1750tnl (50.00%)> ===
f      test |  Pattern: (^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*) : (%1="<100%hp 100%m 100%mv 1750tnl (50.00%)> ", %2="", %3="===")
c      test |  exec : Pattern "(^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*)" : #IF (...
a      test |<100%hp 100%m 100%mv 1750tnl (50.00%)> ===
f      test |  Pattern: (^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*) : (%1="<100%hp 100%m 100%mv 1750tnl (50.00%)> ", %2="", %3="===")
c      test |  exec : Pattern "(^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*)" : #IF (...
a      test |<100%hp 100%m 100%mv 1750tnl (50.00%)> ===
f      test |  Pattern: (^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*) : (%1="<100%hp 100%m 100%mv 1750tnl (50.00%)> ", %2="", %3="===")
c      test |  exec : Pattern "(^(\[0[Sm])?<.*\d+.*\d+.*\d+.*?> )(.*)" : #IF (...
etc
Reply with quote
Dwoggurd
Wanderer


Joined: 29 Jan 2008
Posts: 63

PostPosted: Wed Jun 18, 2008 4:15 pm   
 
Can any gurus comment what's going on here? Why this trigger heavily changes its behaviour when I play with options?
Is it a bug or there are other explanations to it?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Wed Jun 18, 2008 5:35 pm   
 
The answer, broadly, is "don't use #sub in ansi triggers". If you really need to use #sub, use a reparse state attached to the original trigger. Because there're characters in the trigger pattern that don't appear in the text on the screen (or something), it screws up the counting and causes the wrong text to be subbed. So don't use it.

Your third example is, I guess, because the subbed text causes the trigger to fire again. Not sure if that's a bug or not.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Dwoggurd
Wanderer


Joined: 29 Jan 2008
Posts: 63

PostPosted: Mon Jun 23, 2008 10:24 pm   
 
I tried to replace #SUB with #GAG and #SAY.
But it looks like say-text is processed by the same trigger again (and sometimes fall into a loop because of it). Why? I thought that #SAY text should not be parsed.
Or it's some kind of side effect of GAG/SAY pair?
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Mon Jun 23, 2008 10:28 pm   
 
#say is parsed. #print isn't.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Dwoggurd
Wanderer


Joined: 29 Jan 2008
Posts: 63

PostPosted: Mon Jun 23, 2008 10:42 pm   
 
Now I'm confused even more Very Happy
I tried to play with standalone #SAY and my triggers SOMETIMES don't fire at all (as they will fire on #SHOW).
However when I use #SAY after #GAG in my trigger above the script debugger pretends that say-text causes the this trigger to fire again and again.
What is the trick?
Reply with quote
Dwoggurd
Wanderer


Joined: 29 Jan 2008
Posts: 63

PostPosted: Mon Jun 23, 2008 10:51 pm   
 
Hrm, it looks like say inserts ESC[1S before the text so ansi triggers with patterns like ^xxx do not fire and normal triggers fire.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Mon Jun 23, 2008 11:10 pm   
 
Well, that's true! If you are using an ANSI color trigger and you put ^ at the beginning, you are telling CMUD to only trigger on text that has the default color. #SAY doesn't use the default color...it uses the command echo color style. The ESC[1S is this style code. So this actually allows you to create color triggers that only fire on #SAY and not other text. This is a feature.

If you want something to fire on text regardless of color, then don't use an ANSI color trigger.
Reply with quote
Dwoggurd
Wanderer


Joined: 29 Jan 2008
Posts: 63

PostPosted: Mon Jun 23, 2008 11:17 pm   
 
By the way, what is the right way to print something with default color? Right now I'm using #PRINT ESC]0S.... but I feel like a haxor.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Jun 24, 2008 6:43 pm   
 
The #SHOW command will print in the default color. Using ESC[0S is a bad idea since that is an internal ansi code (not a standard) and might change. If you must use styles right now, then the more standard way to do it would be the MXP command:

#MXP <STYLE 0>text</STYLE>

This is the syntax that will be used when user-defined styles are implemented in the future. But for now, #SHOW should work fine.


Last edited by Zugg on Tue Jun 24, 2008 11:55 pm; edited 1 time in total
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue Jun 24, 2008 11:29 pm   
 
Zugg wrote:
The #SHOW command will print in the default color. Using ESC[0S is a bad idea since that is an internal ansi code (not a standard) and might change. If you must use styles right now, then the more standard way to do it would be the MXP command:

#MXP <STYLE 0>text</STYLE>

This is the syntax that will be used when user-defined styles are implemented in the future. But for now, #SHOW should work fine.


Whenever someone posts something that looks a might strange, like Say #MXP with nothing after it, have a look at what it says when you click quote. Usually that will let you see what they actually wrote.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Tue Jun 24, 2008 11:56 pm   
 
Yeah, I always forget that HTML tags are enabled by default for me (as an Admin of the forum)
Reply with quote
Dwoggurd
Wanderer


Joined: 29 Jan 2008
Posts: 63

PostPosted: Wed Jun 25, 2008 3:51 pm   
 
For my purposes I need some way to print text with default or other color which is not processed by triggers. #MXP/#SAY/#SHOW may not be very good for that.
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Jun 25, 2008 4:49 pm   
 
OK, that's actually pretty simple then. Use the %ansi(reset) function to reset the color to the default. This works with #PRINT:

#PRINT {%ansi(reset)This text is in the default color}

That works and prevents you from needing to know the low-level escape codes.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
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

© 2009 Zugg Software. Hosted by Wolfpaw.net