 |
ennye Novice
Joined: 17 Dec 2007 Posts: 49
|
Posted: Sun Jan 13, 2008 1:19 pm
Feature missing. Last line substitute. |
Got a trigger :
place.$ (very simple example)
Want to substitute the whole triggered line with THE SAME line and text added in front of it.
F.e.
This is a very dark place.
I want to get :
[DARK] This is a very dark place.
Now to do this you have to either:
- trigger the whole line and use #su {"[DARK]" %trigger} or
- trigger the start of the line and use #su {"[DARK]" %1}
Why not match ANY part of this phrase and have possibility to substitute the whole matched LINE ?
Why bothering?
-Instead of doing many triggers matching all the lines, you can do 1 trigger with strings matching phrases from any position of that line AND MANIPULATE ALL LAST LINE.
-Why not using gags ? Gag kills original line and echoes a new one. Doesnt anchor the line nor keep line order. In fast text flow gagged lines are echoed delayed.
-Speed purposes. You can do one trigger like {any position|of the|line|start|end|virtually any} and manipulate with #su on the whole matched last line.
Maybe there is any workaround? To substitute last matched LINE, not last matched PATTERN ? NOT USING GAGS |
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jan 13, 2008 2:06 pm Re: Feature missing. Last line substitute. |
ennye wrote: |
Why not match ANY part of this phrase and have possibility to substitute the whole matched LINE ? |
Becuase doing it that way precludes some uses, like, say, if someone had fallen out with me:
#trig {Fang} {#sub Pooface}
It's pretty trivial to make a trigger match a whole line if you need it to. |
|
|
 |
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: Sun Jan 13, 2008 2:23 pm |
Quote: |
-Why not using gags ? Gag kills original line and echoes a new one. Doesnt anchor the line nor keep line order. In fast text flow gagged lines are echoed delayed. |
in zMUD this is true, in CMUD they shouldn't be delayed. CMUD should parse the current line and process all triggers before moving onto the next, so using #GAG should work.
using
Code: |
#TR {^(*)$place.$} {#GAG;#GAG -1;#SHOW {%1 place.}} |
seems to work fine even when receiving lots of lines
Code: |
#ALIAS test {#LOOP 100 {#IF (%random( 1, 10)=10) {
#say This is a very dark
#say place.
} {#say "test123"}}
} |
|
|
_________________ CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;) |
|
|
 |
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Sun Jan 13, 2008 6:56 pm |
One issue with #GAG then #SHOW is that you would lose color info (and perhaps MXP too) in the original text, I would think.
Another workaround you can use is to add a Reparse state in the trigger to select the whole line, then #SUB as you want. This can be useful when it's inconvenient to make the original trigger select the whole line as well. |
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Sun Jan 13, 2008 7:38 pm |
For the specific example given this should work:
Code: |
#TRIGGER {place.$} {#PSUB "[DARK]" 0 0} |
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
ennye Novice
Joined: 17 Dec 2007 Posts: 49
|
Posted: Sun Jan 13, 2008 10:22 pm |
The most important is situation :
Trigger
{place.|garden of|Dungeons of|deep mine} (very important the text is matched from any position of the line)
I want all these lines preceded by [DARK].
If there was a command :
#subline {[DARK] %line} (substituting all partially matched line)
Its just an example i got to substitute around 30 events, some of them i can put in one trigger (because they got constant a few unique first words and i match it and use #su {[DARK] %1}, but half of them got no constant start nor end, i have to prepare one trigger for every pattern. matching all the line and use #su {[DARK] %trigger}. |
|
Last edited by ennye on Sun Jan 13, 2008 10:37 pm; edited 1 time in total |
|
|
 |
ennye Novice
Joined: 17 Dec 2007 Posts: 49
|
Posted: Sun Jan 13, 2008 10:34 pm |
Quote: |
It's pretty trivial to make a trigger match a whole line if you need it to. |
Yea it is. If you operate on every pattern. But try to do this in one trigger using a string list, when constant text in f.e. 50 lines is mixed between start end and middle of the line. You have to prepare 3 groups, and you have no clear and fast possibility to prepare all-line-matching substitution.
Fe:
Instead of doing
{place.|garden of|Dungeons of|deep mine}
and substituting ALL THE MATCHED LINE
You have to do :
^(Dungeons of|Fall of|Anything constant opening line) #su {[DARK] %1}
^* {garden of|deep mine} *.$ #su {[DARK] %trigger}
^* place.$ #su {[DARK] %trigger}
which is VERY BADLY optimized ;) |
|
|
 |
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Mon Jan 14, 2008 1:01 am |
Vijilante wrote: |
For the specific example given this should work:
Code: |
#TRIGGER {place.$} {#PSUB "[DARK]" 0 0} |
|
That would be a great idea, but it doesn't work. It eats the first char. I guess 0 0 means replace starting at 0 and ending at 0, which includes the first char. |
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Mon Jan 14, 2008 1:18 am |
That isn't all that hard to correct, just need to put the first character back as we do it. I am glad someone tested it instead of just ranting. Aslo the reason to use #PSUB instead of #SUB is to preserve colors.
Code: |
#TRIGGER {{place.|garden of|Dungeons of|deep mine}} {#PSUB {%concat("[DARK]",%left(%line,1))} 0 0} |
Anything else we can help with today?
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Mon Jan 14, 2008 1:29 am |
Vijilante wrote: |
That isn't all that hard to correct, just need to put the first character back as we do it. I am glad someone tested it instead of just ranting. Aslo the reason to use #PSUB instead of #SUB is to preserve colors.
Code: |
#TRIGGER {{place.|garden of|Dungeons of|deep mine}} {#PSUB {%concat("[DARK]",%left(%line,1))} 0 0} |
Anything else we can help with today? |
I tried that and you lose the color of the first char, using either:
Code: |
#SHOW {%ansi(red)This is a dark place.}
think %xrThis is a dark place. |
The latter is from a TinyMUSH. |
|
|
 |
ennye Novice
Joined: 17 Dec 2007 Posts: 49
|
Posted: Mon Jan 14, 2008 1:38 am |
Quote: |
#TRIGGER {{place.|garden of|Dungeons of|deep mine}} {#PSUB {%concat("[DARK]",%left(%line,1))} 0 0} |
Nice idea. This is ok for me.
I used (.)$ to substitute with adding at the end of the line. Above we got a way to add before.
Executing this operation : #PSUB {%concat("[DARK]",%left(%line,1))} 0 0} seems to be much faster for script than parsing 50 separate triggers.
How about this color messing ? :> |
|
|
 |
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Mon Jan 14, 2008 4:00 am |
I think I still prefer the Reparse state method. I use that a lot and it preserves colors
In fact I sometimes use multiple such states because at times I have to use #SUB more than once on a single line to replace parts of it, as #SUB lets you put in MXP tags, and #PSUB doesn't (or it didn't used to). |
|
|
 |
|
|