Snippet ColorIt

WolfieeifloW

WEHZ Helper
Reaction score
372
ColorIt v1.0
By: Wolfie[NoCT]


Introduction:
A cool little library made by me.
All you do is input a color and the string you want to color.
There's two different versions (Blue and Red) .


Usage:
JASS:
function ColorIt takes string Color, string Word returns string Colored

It takes a color and the word you want colored.

So in your function, for example:
JASS:
private function Warning takes nothing returns nothing
    call BJDebugMsg(ColorIt("red", "WARNING!"))
endfunction

Where "red" is the color and "WARNING!" is the word you want colored.
That BJDebugMsg() would result in:
Code:
[color=red]WARNING![/color]

An example of ColorIt in action:
JASS:
scope TestColor initializer TCInit

    private function TCActions takes nothing returns nothing
        call DisplayTextToPlayer(Player(0), 0, 0, "Player " + ColorIt("gold", GetPlayerName(GetTriggerPlayer())) + " has asked for " + ColorIt("red", "help") + "!")
        //Display to 'Player 1 (Red)' that the triggering player needs help;
        //The players name will be colored "gold" because of   ColorIt("gold", GetPlayerName(GetTriggerPlayer()))
        //        Tells ColorIt you want the players name colored gold --^                ^-- Tells ColorIt you want the triggering players name colored
        
        //The text "help" will be colored "red" because of     ColorIt("red", "help")
        //                Tells ColorIt you want your text colored red --^      ^-- Tell ColorIt you want the text "help" colored
    endfunction
        
//====================================================================================================
    private function TCInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        loop
           call TriggerRegisterPlayerChatEvent(t, Player(i), "-help", true) //Register if a player types "-help"
           set i = i + 1
        exitwhen i == bj_MAX_PLAYER_SLOTS
        endloop
        call TriggerAddAction(t, function TCActions)
    endfunction

endscope



Code:
ColorIt Blue:
JASS:
// +------------------------------------------------------------+
// |                                                            |
// |                  -=-=- ColorIt Blue -=-=-                  |
// |                -=-=- By Wolfie[NoCT] -=-=-                 |
// |                    Requires Jass NewGen                    |
// |                                                            |
// +------------------------------------------------------------+
// |                                                            |
// |   ColorIt Blue;                                            |
// |      - Provides an easier way to manage colors             |
// |      - Uses a loop to check for a valid color              |
// |                                                            |
// +------------------------------------------------------------+
library ColorItBlue initializer CIBInit

// +---------------------------------+
// |     -=-=- MODIFY HERE -=-=-     |
// |     -=-=- MODIFY HERE -=-=-     |
// |     -=-=- MODIFY HERE -=-=-     |
// +---------------------------------+
    globals
        constant integer COLORSNUM = 40
        //Change this to the number of array slots used
        
        constant string DEFAULT = "ffffff"
        //Change this to the color you want strings to
        //Default to if users enter an invalid color
        
        //Don't touch these!
        string array COLORNAME//Don't touch these!
        string array COLORCODE//Don't touch these!
        //Don't touch these!
    endglobals
    
// +--------------------------------------------------------------+
// |            Set the colors name into COLORNAME[]              |
// |        Set the hexcode of the color into COLORCODE[]         |
// |   Remember to change COLORSNUM to the number of slot used!   |
// +--------------------------------------------------------------+
    function CIBActions takes nothing returns nothing
        set COLORNAME[0] = "aqua"
        set COLORCODE[0] = "00ffff"
        set COLORNAME[1] = "azure"
        set COLORCODE[1] = "f0ffff"
        set COLORNAME[2] = "beige"
        set COLORCODE[2] = "f5f5dc"
        set COLORNAME[3] = "black"
        set COLORCODE[3] = "000000"
        set COLORNAME[4] = "blue"
        set COLORCODE[4] = "0000ff"
        set COLORNAME[5] = "brown"
        set COLORCODE[5] = "a52a2a"
        set COLORNAME[6] = "coral"
        set COLORCODE[6] = "ff7f50"
        set COLORNAME[7] = "crimson"
        set COLORCODE[7] = "dc143c"
        set COLORNAME[8] = "cyan"
        set COLORCODE[8] = "99b4d1"
        set COLORNAME[9] = "darkblue"
        set COLORCODE[9] = "00008b"
        set COLORNAME[10] = "darkgreen"
        set COLORCODE[10] = "006400"
        set COLORNAME[11] = "darkorange"
        set COLORCODE[11] = "ff8c00"
        set COLORNAME[12] = "darkred"
        set COLORCODE[12] = "8b0000"
        set COLORNAME[13] = "gold"
        set COLORCODE[13] = "ffd700"
        set COLORNAME[14] = "grey"
        set COLORCODE[14] = "808080"
        set COLORNAME[15] = "green"
        set COLORCODE[15] = "008000"
        set COLORNAME[16] = "hotpink"
        set COLORCODE[16] = "ff0099"
        set COLORNAME[17] = "indigo"
        set COLORCODE[17] = "4b0082"
        set COLORNAME[18] = "lavender"
        set COLORCODE[18] = "e6e6fa"
        set COLORNAME[19] = "lightblue"
        set COLORCODE[19] = "add8e6"
        set COLORNAME[20] = "lime"
        set COLORCODE[20] = "00ff00"
        set COLORNAME[21] = "magenta"
        set COLORCODE[21] = "ff00ff"
        set COLORNAME[22] = "maroon"
        set COLORCODE[22] = "800000"
        set COLORNAME[23] = "navy"
        set COLORCODE[23] = "000080"
        set COLORNAME[24] = "olive"
        set COLORCODE[24] = "808000"
        set COLORNAME[25] = "orange"
        set COLORCODE[25] = "ffa500"
        set COLORNAME[26] = "orchid"
        set COLORCODE[26] = "da70d6"
        set COLORNAME[27] = "pink"
        set COLORCODE[27] = "ffc0cb"
        set COLORNAME[28] = "plum"
        set COLORCODE[28] = "dda0dd"
        set COLORNAME[29] = "purple"
        set COLORCODE[29] = "800080"
        set COLORNAME[30] = "red"
        set COLORCODE[30] = "ff0000"
        set COLORNAME[31] = "salmon"
        set COLORCODE[31] = "fa8072"
        set COLORNAME[32] = "silver"
        set COLORCODE[32] = "c0c0c0"
        set COLORNAME[33] = "snow"
        set COLORCODE[33] = "fffafa"
        set COLORNAME[34] = "tan"
        set COLORCODE[34] = "d2b48c"
        set COLORNAME[35] = "teal"
        set COLORCODE[35] = "008080"
        set COLORNAME[36] = "tomato"
        set COLORCODE[36] = "ff6347"
        set COLORNAME[37] = "turquoise"
        set COLORCODE[37] = "40e0d0"
        set COLORNAME[38] = "violet"
        set COLORCODE[38] = "ee82ee"
        set COLORNAME[39] = "yellow"
        set COLORCODE[39] = "ffff00"
        //set COLORNAME[40] = "ColorName"
        //set COLORCODE[40] = "ColorCode"
        //[...]
    endfunction
    
// +------------------------------------------+
// |     -=-=- NO TOUCHIE PAST HERE -=-=-     |
// |     -=-=- NO TOUCHIE PAST HERE -=-=-     |
// |     -=-=- NO TOUCHIE PAST HERE -=-=-     |
// +------------------------------------------+
    function ColorIt takes string Color, string Word returns string Colored
        local integer i = 0
        local boolean cc = false
        
        loop
        exitwhen i == COLORSNUM
            if (Color != COLORNAME<i>) then
                set cc = false
            else
                return (&quot;|cff&quot; + COLORCODE<i> + Word + &quot;|r&quot;)
            endif
            set i = i + 1
        endloop
        return (&quot;|cff&quot; + DEFAULT + Word + &quot;|r&quot;)
    endfunction
    
//====================================================================================================
    private function CIBInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call TriggerRegisterTimerEvent(t, 0.01, false)
        call TriggerAddAction(t, function CIBActions)
    endfunction
    
endlibrary</i></i>

ColorIt Red:
JASS:
// +------------------------------------------------------------+
// |                                                            |
// |                  -=-=- ColorIt Red -=-=-                   |
// |                -=-=- By Wolfie[NoCT] -=-=-                 |
// |                    Requires Jass NewGen                    |
// |                                                            |
// +------------------------------------------------------------+
// |                                                            |
// |   ColorIt Red;                                             |
// |      - A more advanced version                             |
// |      - Utilizes Elseif&#039;s to return values                  |
// |                                                            |
// +------------------------------------------------------------+
library ColorItRed

    globals
        constant string DEFAULT = &quot;|cffffffff&quot;
    endglobals

    function ColorIt takes string Color, string Word returns string Colored
        if (Color == &quot;aqua&quot;) then
            return (&quot;|cff00ffff&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;azure&quot;) then
            return (&quot;|cfff0ffff&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;beige&quot;) then
            return (&quot;|cfff5f5dc&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;black&quot;) then
            return (&quot;|cff000000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;blue&quot;) then
            return (&quot;|cff0000ff&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;brown&quot;) then
            return (&quot;|cffa52a2a&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;coral&quot;) then
            return (&quot;|cffff7f50&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;crimson&quot;) then
            return (&quot;|cffdc143c&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;cyan&quot;) then
            return (&quot;|cff99b4d1&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;darkblue&quot;) then
            return (&quot;|cff00008b&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;darkgreen&quot;) then
            return (&quot;|cff006400&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;darkorange&quot;) then
            return (&quot;|cffff8c00&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;darkred&quot;) then
            return (&quot;|cff8b0000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;gold&quot;) then
            return (&quot;|cffffd700&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;grey&quot; or Color == &quot;gray&quot;) then
            return (&quot;|cff808080&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;green&quot;) then
            return (&quot;|cff008000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;hotpink&quot;) then
            return (&quot;|cffff0099&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;indigo&quot;) then
            return (&quot;|cff4b0082&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;lavender&quot;) then
            return (&quot;|cffe6e6fa&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;lightblue&quot;) then
            return (&quot;|cffadd8e6&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;lime&quot;) then
            return (&quot;|cff00ff00&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;magenta&quot;) then
            return (&quot;|cffff00ff&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;maroon&quot;) then
            return (&quot;|cff800000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;navy&quot;) then
            return (&quot;|cff000080&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;olive&quot;) then
            return (&quot;|cff808000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;orange&quot;) then
            return (&quot;|cffffa500&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;orchid&quot;) then
            return (&quot;|cffda70d6&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;pink&quot;) then
            return (&quot;|cffffc0cb&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;plum&quot;) then
            return (&quot;|cffdda0dd&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;purple&quot;) then
            return (&quot;|cff800080&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;red&quot;) then
            return (&quot;|cffff0000&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;salmon&quot;) then
            return (&quot;|cfffa8072&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;silver&quot;) then
            return (&quot;|cffc0c0c0&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;snow&quot;) then
            return (&quot;|cfffffafa&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;tan&quot;) then
            return (&quot;|cffd2b48c&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;teal&quot;) then
            return (&quot;|cff008080&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;tomato&quot;) then
            return (&quot;|cffff6347&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;turquoise&quot;) then
            return (&quot;|cff40e0d0&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;violet&quot;) then
            return (&quot;|cffee82ee&quot; + Word + &quot;|r&quot;)
        elseif (Color == &quot;yellow&quot;) then
            return (&quot;|cffffff00&quot; + Word + &quot;|r&quot;)
        //elseif (Color == &quot;ColorName&quot;) then
            //return (&quot;ColorCode&quot; + Word + &quot;|r&quot;)
        else
            return (DEFAULT + Word + &quot;|r&quot;)
        endif
    endfunction
    
endlibrary



NOTE: If someone can make a Hexcode converter for this that would be awesome;
Eg. The user types in "red" and the converter retrieves "|cffff0000".
 

Attachments

  • opt-Color_It_v10.w3m
    14.6 KB · Views: 241

WolfieeifloW

WEHZ Helper
Reaction score
372
I wouldn't want to have to implement another system just to use this one?
I think the arrays are fine;
It's not hard to add more colors and I don't think anyone if going to add 8190 colors.
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Then you'd have 39 constants in your trigger instead of adding in a library though?

Sorry if I'm misunderstanding;
I'm still new to JASS.
 

Kabalsin

New Member
Reaction score
2
You should make a better documentation.

Also there is lots of other things that do the same thing, isn't?
 

Azlier

Old World Ghost
Reaction score
461
Constants are indeed a better idea. If you're taking colors from player chat, however, Table is what you need.
 

Azlier

Old World Ghost
Reaction score
461
You don't need to learn structs to learn Table.

JASS:
globals
    private Table lol
endglobals

private function What takes nothing returns nothing
    set lol[&quot;MyString&quot;] = //Integer
    //Attaching.
    return lol[&quot;MyString&quot;]
    //Retrieving.
endfunction

private function Init takes nothing returns nothing
     set lol = Table.create()
endfunction
 

WolfieeifloW

WEHZ Helper
Reaction score
372
JASS:
set lol[&quot;MyString&quot;] =

:confused: ?
Should it be like:
JASS:
set lol[&quot;MyString&quot;] = &quot;|cffffffff&quot;

Or something?
 

Azlier

Old World Ghost
Reaction score
461
Did you not see //Integer? It accepts integers only. Like an array index, possibly. Complicates things a bit, I suppose.

JASS:
set lol[&quot;red&quot;] = 0
//Attach.
return ColorStringArray[lol[&quot;red&quot;]]
//Retrieve.


EDIT: Oh wait, nevermind. You need a StringTable. Tables only take integers. :p
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Bah;
I don't see how this would help though?
Don't I still have to set red to the hexcode?
And then set all the "lol[]"s to their colors?
 

Azlier

Old World Ghost
Reaction score
461
Yes. But retrieving them is faster. And retrieving is where speed matters.
 

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
I guess you never saw my Adv Strings system :p

http://www.thehelper.net/forums/showthread.php?t=102161

JASS:
call BJDebugMsg(red + &quot;Error: &quot;+ end + green + &quot;Invalid target chosen for &quot; + end + blue + &quot;Sacrifice!&quot; + end)


It just seems to be more readable to me when you have the colors spaced out like a sentence.

I don't think you're going to have tons of colors being used in a map, so it seems to make sense to have it as an add-as-you-need basis as I did in mine. The only real problem I see with mine is the ugly "end" you have to add to *end* a color (though one might consider that an easy way to distinguish the ending of one color to the beginning of another).
 

Romek

Super Moderator
Reaction score
964
> it won't compile:
You mean, it shouldn't compile.
That does compile, but I do suggest you fix that anyway, Wolfie.

Oh, and the red version is somewhat useless when you can use arrays or table.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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