|
Death Apprentice
Joined: 25 Jun 2002 Posts: 109 Location: USA
|
Posted: Mon Mar 17, 2003 5:39 am
advanced backwards string script |
I've been playing around looking at some of the other backwards stuff around here. And like the other scripts, I can get it to display whole words backwards. But I wanted to display it letter by letter backwards. But add a twist to it, if I wanted to add color to the letters, wanted the color to be attached to the same letter.
Color codes are used with the preceding character {.
So an example of a text with color added would be...
say {RHi {BThere{G!{x displaying You say 'Hi There!
I was thinkin of having an alias called broad (short for broadcast)
that would capture the channel/command you want it to use, then the text.
broad say hi there
broad gossip hi there
etc.
Now, back with the color and stuff, if I were to add color to the broad..
broad say {Rhi {Bthere{x
When it flips all the text letter by letter backwards, if the color codes would still be in the right position where they were layed out in the broad alias.
If anyone can point me in a good direction with some pointers or help me write some of this out, that would be really cool. Thanks if anyone replies.
-Death
-=Realms of the Forgotten=-
site: www.rotf.net
connect: rotf.net:5000 |
|
|
|
Charbal GURU
Joined: 15 Jun 2001 Posts: 654 Location: USA
|
Posted: Mon Mar 17, 2003 6:02 am |
Shouldn't be too hard to do, especially if you have a generic script to reverse text already.
Basically, one relatively easy way of doing this would to be to build up a second copy of what to output.
Initialize a variable to contain the default color code (say, {D) and another variable (called the buffer) to be a null string. The buffer is where we will build up another copy of the string.
Just keep on adding a character at a time to the buffer until you get to a color code. Now, add the contents of the color code variable in reverse and put the color code you just found in the variable. Repeat this paragraph until you reach the end of your text.
Then add the color code in the variable in reverse.
The buffer variable now has the text in order but has moved all the color codes to be directly after the text they are supposed to effect and they are also reversed. So if we run a generic reverse on this buffer variable, we end up with a string that has color codes (not reversed) in front of the text we want them to effect which is exactly what we want.
That's a generally outline of one way to do it. If you need help coding it up, feel free to post again.
- Charbal |
|
|
|
Death Apprentice
Joined: 25 Jun 2002 Posts: 109 Location: USA
|
Posted: Mon Mar 17, 2003 7:10 am |
Yes, please. I'm new to the whole string list thing with buffers and everything. I've come to be quite good at other stuff, but there's also quite a bit that still eludes me.
-Death
-=Realms of the Forgotten=-
site: www.rotf.net
connect: rotf.net:5000 |
|
|
|
Charbal GURU
Joined: 15 Jun 2001 Posts: 654 Location: USA
|
Posted: Mon Mar 17, 2003 8:45 am |
Okay, this should work for you:
#CLASS {ReverseColor}
#ALIAS revcolor {#VARIABLE CurrCode @DefaultCode;#VARIABLE Buffer %null;#VARIABLE Index 1;#WHILE (@Index <= %len( "%-1")) {#VARIABLE Matched %null;#FORALL @ColorCodes {#IF ({%copy( "%-1", @Index, %len( %i))} = {%i}) {#VARIABLE Matched {%i}}};#IF (@Matched = %null) {#VARIABLE Buffer %concat( @Buffer, %copy( "%-1", @Index, 1));#ADD Index 1} {#LOOP %len( @CurrCode),1 {#VARIABLE Buffer %concat( @Buffer, %copy( @CurrCode, %i, 1))};#VARIABLE CurrCode @Matched;#ADD Index %len( @Matched)}};#IF (@CurrCode <> %null) {#LOOP %len( @CurrCode),1 {#VARIABLE Buffer %concat( @Buffer, %copy( @CurrCode, %i, 1))}};#VARIABLE Matched %null;#LOOP %len( @Buffer),1 {#VARIABLE Matched %concat( @Matched, %copy( @Buffer, %i, 1))};#VAR Buffer @Matched}
#VAR DefaultCode "{D"
#VAR ColorCodes "{R|{B|{G|{Y|{D"
#VAR Matched {}
#VAR Buffer {}
#ALIAS broad {revcolor "%-2";%1 @Buffer}
#CLASS 0
Just modify DefaultCode and the ColorCodes stringlist to whatever is necessary.
You should then be able to use the broad alias just as you've specified.
Edit: this script doesn't seem to like commas. I should be able to fix it tomorrow if no one else does in the meantime.
- Charbal |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Mon Mar 17, 2003 6:42 pm |
The problem is in the functions. Functions use commas to separate fields. When you manipulate text using functions, you'll almost always have difficulty with commas. I don't know of any good solutions. I usually try to stay away from %concat.
LightBulb
Advanced Member |
|
|
|
Kjata GURU
Joined: 10 Oct 2000 Posts: 4379 Location: USA
|
Posted: Mon Mar 17, 2003 8:19 pm |
You could always replace the commas with some other character (printable or not) and then replace them back at the end.
Kjata |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Tue Mar 18, 2003 3:59 am |
You could always ask the guy who wrote the GENERIC backwords script...
me
megamog75
Keeper of the only printable help files for Zmud. |
|
|
|
Death Apprentice
Joined: 25 Jun 2002 Posts: 109 Location: USA
|
Posted: Tue Mar 18, 2003 4:30 am |
It's working via characters going backwards, but if i throw in color it goes haywire. Or, even if I don't add in color it seems to spaz out a little.
broad say hi there -> say {Dereht ih -> You say 'ereht ih'
broad say {Rtest{Bing {Gcol{Yor{x -> spammed #VARIABLE repeatidly
-=Realms of the Forgotten=-
site: www.rotf.net
connect: rotf.net:5000 |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Tue Mar 18, 2003 5:51 am |
The problem lies in the way your coloring your text.
Emample:
#CO {hi} red
or
#CO {you} blue
When it comes out backwards it can not reconize it.
you would need
#CO {IH} red
or
#CO {UOY} blue
to get it right
I think more of your script for coloring would be needed before anyone can really help you..:)
megamog75
Keeper of the only printable help files for Zmud. |
|
|
|
Death Apprentice
Joined: 25 Jun 2002 Posts: 109 Location: USA
|
Posted: Tue Mar 18, 2003 8:55 pm |
I'm coloring my text with my muds color syntax...
{r dark red (lower case) {R bright red (upper case)
{m dark magenta (lower case) {M bright magenta (upper case)
{g dark green (lower case) {G bright green (upper case)
{c dark cyan (lower case) {C bright cyan (upper case)
{y dark yellow (lower case) {Y bright yellow (upper case)
{w dark white (lower case) {W bright white (upper case)
{b dark blue (lower case) {B bright blue (upper case)
{D dark grey (upper case) {x reset colour (lower case)
not zmud's #co syntax
-=Realms of the Forgotten=-
site: www.rotf.net
connect: rotf.net:5000 |
|
|
|
Charbal GURU
Joined: 15 Jun 2001 Posts: 654 Location: USA
|
Posted: Wed Mar 19, 2003 8:32 am |
I never actually tested the broad alias. It is simple enough that it should be clear that it should be bug-free but zMUD has some parsing idiosyncracies that created this issue.
So change the line
revcolor "%-2"
to read:
#EXEC %concat("revcolor ", "%-2")
Retesting what I had posted, I couldn't find any issues with the commas. I think what I meant is quotes. And I don't think that will change any time soon since zMUD interprets them as ends of the literal string instead of characters.
Responding to Lightbulb, I've counteracted that tendency of zMUD by enclosing my % references in quotes whenever I use them.
Some other available techniques are the use of %literal and controlled usage of %expand.
- Charbal |
|
|
|
megamog75 Enchanter
Joined: 20 Nov 2002 Posts: 627 Location: USA
|
Posted: Thu Mar 20, 2003 12:04 am |
So just to clarify,you are sending text backwards to the mud and your color script is not reconizing the output?
But it does reconive forward text.
This may be because of a bug in Zmud, it seems that sometimes there can not be two
Trigger's with the same name :
#trig {nothing} {something}
#trig {nothing} {something else}
I have never been able to get this to work so I just work with it.
Change the #trig that colors the letters
from #TRIGGER to #ONINPUT
This should clear it up.
megamog75
Keeper of the only printable help files for Zmud. |
|
|
|
Charbal GURU
Joined: 15 Jun 2001 Posts: 654 Location: USA
|
Posted: Thu Mar 20, 2003 1:11 am |
As I understand it, the color codes are not supposed to be parsed by zMUD. In many MUDs, you use notation like Death has shown to produce colors on the MUD.
You send something like {R and the MUD converts it to an ANSI color sequence before sending it to other users. In other words, it's not a zMUD script that is creating the colors. But these special codes cannot be reversed like other characters because they would then lose their special significance to the MUD (ie, R{ means nothing to the MUD). So my script is a way to reverse text while making the color codes apply to the same regions that they would in the forward text.
- Charbal |
|
|
|
Death Apprentice
Joined: 25 Jun 2002 Posts: 109 Location: USA
|
Posted: Thu Mar 20, 2003 1:39 am |
Thank you Charbal so much! I added the color codes to the one stringlist of them and changed the one thing you had and it works wonders! even with the color codes for blinking when i added it in :)
-Death
-=Realms of the Forgotten=-
site: www.rotf.net
connect: rotf.net:5000 |
|
|
|
|
|