|
Delphi03 Novice
Joined: 20 Aug 2004 Posts: 37 Location: Illinois
|
Posted: Fri Apr 02, 2010 6:08 am
[Solved] Text Replace/Function Call |
I have the following trigger:
Code: |
#trigger {(.*)} {#substitute %replace(%1, ^F, @randHigh())} |
and the following function:
Code: |
#function randHigh {#return %case(%random(1,4), %ansi(high, blue), %ansi(high, cyan), %ansi(high, green), %ansi(high, red))} |
This works well enough. It picks a random color from the 4 listed whenever there is an incoming ^F; however, it replaces all of the ^F it finds in that pass with the same color.
Would there be any way to make it choose a random color each time it encounters an ^F without changing the above-listed trigger? (it's part of a larger replacement trigger that I have as-of-yet been unable to find a better solution for). |
|
Last edited by Delphi03 on Fri Apr 02, 2010 4:04 pm; edited 1 time in total |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Fri Apr 02, 2010 2:12 pm |
Something like this (throwing this together without testing):
Code: |
$text = %1
#WHILE (%match($text,"\^F")) {
$pos = %match($text,"\^F")
$text = %delete($text,$pos,2)
$text = %insert($text,@randHigh())
}
#substitute $text
|
|
|
Last edited by Rahab on Fri Apr 02, 2010 2:19 pm; edited 1 time in total |
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Fri Apr 02, 2010 2:17 pm |
Ahh. What you want to do, is instead of replace, use subregex.
#trigger {(.*)} {#substitute %subregex(%1, "(\^F)", @randHigh())} |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Fri Apr 02, 2010 2:21 pm |
No, %subregex will replace all of them identically, just like %replace.
|
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Fri Apr 02, 2010 2:25 pm |
Hmm, you're right. Because its calling the function.
|
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Fri Apr 02, 2010 2:38 pm |
However, there is a way around that. By delaying the point at which the function @RandHigh is expanded.
With quotes, like so:
#trigger {(.*)} {#substitute %subregex(%1, "(\^F)", "@RandHigh()")} |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Fri Apr 02, 2010 2:44 pm |
ooh! Clever! that might work with %replace, too.
|
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Fri Apr 02, 2010 2:46 pm |
Actually yeah, it would, lol.
|
|
|
|
Delphi03 Novice
Joined: 20 Aug 2004 Posts: 37 Location: Illinois
|
Posted: Fri Apr 02, 2010 3:09 pm |
Danlo wrote: |
However, there is a way around that. By delaying the point at which the function @RandHigh is expanded.
With quotes, like so:
#trigger {(.*)} {#substitute %subregex(%1, "(\^F)", "@RandHigh()")} |
I tried this, but it did not work. It simply replaced all instances with ^F with @randHigh() (literally, the text, @randHigh()). |
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Fri Apr 02, 2010 3:27 pm |
Really? It doesn't do that for me. It expands it just fine. Hmmm. Maybe a setting somewhere.
|
|
Last edited by Danlo on Fri Apr 02, 2010 3:30 pm; edited 1 time in total |
|
|
|
Delphi03 Novice
Joined: 20 Aug 2004 Posts: 37 Location: Illinois
|
Posted: Fri Apr 02, 2010 3:28 pm |
Using CMUD 3.16b currently.
|
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Fri Apr 02, 2010 3:33 pm |
Try this one:
#trigger {(.*)} {#substitute %subregex(%1, "(\^F)", "@RandHigh")}
Or this one:
#trigger {(.*)} {#substitute %subregex(%1, "(\^F)", "%expand(@RandHigh)")}
This is probably the most likely variation to work:
#trigger {(.*)} {#substitute %subregex(%1, "(\^F)", %expand("@RandHigh()"))} |
|
|
|
Delphi03 Novice
Joined: 20 Aug 2004 Posts: 37 Location: Illinois
|
Posted: Fri Apr 02, 2010 3:46 pm |
Danlo wrote: |
This is probably the most likely variation to work:
#trigger {(.*)} {#substitute %subregex(%1, "(\^F)", %expand("@RandHigh()"))} |
This one worked just fine, thank you.
As a side note, this does not work with %replace(), only %subregex()...or at least in my experience thus far. |
|
|
|
Danlo Magician
Joined: 28 Nov 2003 Posts: 313 Location: Australia
|
Posted: Fri Apr 02, 2010 4:00 pm |
Yeah, there's a slight difficulty with %replace turning it into a string and stopping it from further expansion, even %eval wouldn't expand it further, however, the %exec function was able to force it through some more expansion, so you ended up with:
#trigger {(.*)} {#substitute %exec(%replace(%1, "^F", "@RandHigh"))} |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Fri Apr 02, 2010 6:32 pm |
Here's an even slicker way to do it:
#trigger {^F} {#sub {@randHigh()}}
Make sure the Repeat within line trigger option is checked. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
|
|