Snippet Color Code String

Nestharus

o-o
Reaction score
84
Someone else wrote this before and we argued that it wouldn't be useful for save/load, but with the above 2 scripts, I figured it would be useful. His was a bit different, including global constants. Mine uses pure locals for more dynamism.

It is better to color using BigInt digits directly, but since EncryptNumber returns a string this is now ok I suppose ;p.

JASS:

library ColorCodeString
    function ColorCodeString takes string s, string numColor, string lowerColor, string upperColor, string specColor, integer start returns string
        local string ns = ""
        local string c
        local integer m = StringLength(s)
        local integer i = start
        local boolean l
        loop
            exitwhen m == i
            
            set c = SubString(s,i,i+1)
            
            if (c!=" ") then
                set l=StringCase(c,false)==c
                
                //special or number
                if (c==StringCase(c,true) and l) then
                    //number
                    if ("0"==c or 0!=S2I(c)) then
                        set ns=ns+"|cff"+numColor+c
                    //special
                    else
                        set ns=ns+"|cff"+specColor+c
                    endif
                //lowercase
                elseif (l) then
                    set ns=ns+"|cff"+lowerColor+c
                //uppercase
                else
                    set ns=ns+"|cff"+upperColor+c
                endif
            else
                set ns=ns+" "
            endif
            
            set i = i + 1
        endloop
        return ns
    endfunction
endlibrary


Demo
[ljass]call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60,ColorCodeString("1 n N !", "40e0d0", "ff69b4", "00AA00", "ffff00",0))[/ljass]
 

tooltiperror

Super Moderator
Reaction score
231
No description, no implementation instructions, no demo map. Excellent.
 

luorax

Invasion in Duskwood
Reaction score
67
Most likely because it's a simple function.
This is supposed to colorize save codes.

However, I think if I'd have to input "|cff" too, it'd be much more readable (personal opinion). Also, an ARGB version would be also nice.
 

Nestharus

o-o
Reaction score
84
Well, I was thinking of renaming it ColorCodeString to apply color coding for the various types of characters = ).


Also, for me, passing in the hex values as strings is more readable.


If you want a hex version, write another function and submit it as its own resource that's like ColorCodeStringHex ; ).
 

tooltiperror

Super Moderator
Reaction score
231
Color String is a way too generic name. Give it a name with meaning, like [LJASS]ColorSaveLoadCode(String)[/LJASS].
 

Nestharus

o-o
Reaction score
84
I did ColorCodeString, referring to color codes for characters.


I can't change the thread name. I changed the resource name way before you posted what you did ;p.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top