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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Fri Apr 08, 2005 8:38 am   

SLOW script
 
--- begin colorsay alias ---
current_sentance = %null
word_array = %replace( %0, " ", |)
#FORALL ord_array {
#LOOP 0,%len( %i) {
which_color = %random( 1, 14)
current_sentance = %additem( ~@, @current_sentance)
current_sentance = %additem( %item( @color_list, @which_color),
@current_sentance)
current_sentance = %additem( %left( %right( %i, %j), 1),
@current_sentance)
}
}
say %replace( %replace( @current_sentance, -|-|, " "), |, "")
--- end colorsay alias ---


this script will say your sentance with each character having a random color,

the one variable with info in it is @color_list, it has in it:
r|R|b|B|c|C|m|M|y|Y|g|G|w|W


to send a color to the mud you precede it with ~@R for bright red

Several problems i cant seem to fix are:

#1 it is SLOW, takes like 10 seconds to process an average sentance
#2 commas as input halt processing
#3 somthig in this "colorsay test! # $ % ^ & * ( ) ~{ } ~[ ]" says it correctly but beforehand tries to send this command to the mud twice:

{which_color = 3;current_sentance = @|c|t|@|m|e|@|Y|s|@|W|t|@|Y|!|@|y||@|W|#|@|m||@|W|$|@|r||@|B|%|@|B||@|y|^|@|C||@|m|&|@|Y||@|M|*|@|c||@|G|(|)|@|w||@|w|{}|@;current_sentance = @|c|t|@|m|e|@|Y|s|@|W|t|@|Y|!|@|y||@|W|#|@|m||@|W|$|@|r||@|B|%|@|B||@|y|^|@|C||@|m|&|@|Y||@|M|*|@|c||@|G|(|)|@|w||@|w|{}|w;current_sentance = 1), 1), @|c|t|@|m|e|@|Y|s|@|W|t|@|Y|!|@|y||@|W|#|@|m||@|W|$|@|r||@|B|%|@|B||@|y|^|@|C||@|m|&|@|Y||@|M|*|@|c||@|G|(|)|@|w||@|w|{})}


i figure the way i select xth letter from the words using %left/%right nested is the slowdown... but i cant seem to find a function to select xth letter from a word directly.

Anyone have a better way to randomly color letters for output to channels?

Thanks
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Fri Apr 08, 2005 9:43 am   
 
I have been playing some with it. This should run faster, and work with commas. However what causes issues in your third example is the text "[ ]" which in zScript means evaluation. For example you can make trigger commands such as "#show [1+2]" and it would show 3.

It almost feels like a bug that you cant escape the brackets using ~. However the [] syntax is rarely used (unfortunately) in scripts so you can probably turn it off if you want. Go to View->Preferences->General->Script Parser and then uncheck "Allow [] for eval".

#CLASS {saycolor}
#ALIAS saytest {message = %subregex( "%-1", "(.)", "@addcolor(~"%%1~")")}
#VAR color_list {r|R|b|B|c|C|m|M|y|Y|g|G|w|W}
#FUNC addcolor {%if( "%1"="", " ", %concat( "~@", %item( @color_list, %random( 1, %numitems( @color_list))), "%1"))}
#VAR message {}
#CLASS 0

Used Pretty Print
Syntax Colourizer

The above script places the output in the variable 'message'. Example:
saytest hello
Reply with quote
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Fri Apr 08, 2005 10:27 am   
 
changed message to colored_message as message is used elsewhere,
added "say @colored_message" to the alias, changed the bit in the function to %random( 1, 14) as the # wont change... before my changes and after here are results(both same)

command: colorsay testing 1 2 3

sends command: say ~~~~~~~ ~ ~ ~

Mud Outputs: You say '------- - - -'

looks like it converts all characters to ~

bummer

edit: as a side note... it's fast :P

edit2: also the actual colored_message variable contains:
~@b~@G~@w~@C~@R~@W~@b ~@C ~@r ~@b
Reply with quote
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Fri Apr 08, 2005 11:43 am   
 
Semi fixed the issue, but spaces dissapear now:

#CLASS ColorTalk
#ALIAS colorsay {colored_message = %subregex( "%-1", "(.)", "@addcolor(~"%%1~")");say %replace( %replace( @colored_message, ~|~|, " "), |, "")}
#FUNC addcolor {%concat( %item( @color_list, %random( 1, 14)), "%1")}
#VAR colored_message empty
#VAR color_list {(@|r)|(@|R)|(@|b)|(@|B)|(@|c)|(@|C)|(@|m)|(@|M)|(@|y)|(@|Y)|(@|g)|(@|G)|(@|w)|(@|W)}
#CLASS 0

Command: colorsay 1 2 3
Command sent to mud: say @ct@Ge@ws@rt@Wi@wn@mg@W@c1@m@C2@m@Y3
Output: You say 'testing123' <--- whee, random colored :)

Variable colored_message contains: @|ct@|Ge@|ws@|rt@|Wi@|wn@|mg@|W@|c1@|m@|C2@|m@|Y3

Only big issue now is the lack of spacing,,, but it is VERY fast
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Fri Apr 08, 2005 12:01 pm   
 
I have fixed all the issues now I think:
#CLASS {color}
#ALIAS colorsay {say %expand( %subregex( "%-1", "(.)", "@addcolor(~"%%1~")"), 1)}
#VAR color_list {r|R|b|B|c|C|m|M|y|Y|g|G|w|W}
#FUNC addcolor {%if( "%1"="", " ", %concat( "@", %item( @color_list, %random( 1, %numitems( @color_list))), "%1"))}
#CLASS 0

Example: saytest testing 1 2 3
Outputs: say @mt@ye@Gs@yt@bi@mn@Gg @m1 @C2 @g3

Edit: I removed the message variable altogether for faster execution.
Reply with quote
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Fri Apr 08, 2005 12:08 pm   
 
OK, that is it, did a bunch of replaces as a space showed up as 2 colorcodes in a row, lenghty but easy enough to fix... Altered the say in colorsay alias to read:

say %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( %replace( @colored_message, ~|~|, " "), |, ""), "@r@", "@r @"), "@R@", "@R @"), "@b@", "@b @"), "@B@", "@B @"), "@c@", "@c @"), "@C@", "@C @"), "@m@", "@m @"), "@M@", "@M @"), "@y@", "@y @"), "@Y@", "@Y @"), "@g@", "@g @"), "@G@", "@G @"), "@w@", "@w @"), "@W@", "@W @")

Commas and /most/ special characters work cept the [] :P

Couldnt have figured it out without ya Rorso, THANKS!
Reply with quote
Private
Adept


Joined: 10 Jan 2002
Posts: 264
Location: USA

PostPosted: Fri Apr 08, 2005 12:24 pm   
 
Sorry Rorso... your edited script displays:

You say '@|Gt@|Me@|rs@|Rt@|Yi@|cn@|bg @|m1 @|G2 @|g3'

for colorsay testing 1 2 3 :(

mine has all those replaces... but itll work for me :)

Thanks Anyways
Reply with quote
Rorso
Wizard


Joined: 14 Oct 2000
Posts: 1368

PostPosted: Fri Apr 08, 2005 12:27 pm   
 
Thats pretty odd because my script works for me. It could be how you are entering the script into zMUD. My script should not be entered using the command line.

In either case I am glad you found a method that works.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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