String Coloring function Failing

ShadowInTheD

Active Member
Reaction score
12
I made a function to color an inputted string (for a save/load code) and I don't think it's returning a value, and if it is, the value is "". It's supposed to color every character of an inputted string depending on the character type (i.e. numbers, uppercase letters, lowercase letters, symbols).

Here's my function

JASS:
function SaveStringColor takes string saveString returns string
  local string array a
  local integer charCounter = 0
  local string alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$^&*?"
  local integer alphabetCounter = 0
  local string Code = ""
    loop
      exitwhen charCounter > 47
        set a[charCounter] = SubString(saveString,charCounter,charCounter+1)
        loop
          if a[charCounter] == SubString(alphabet,alphabetCounter,alphabetCounter+1) then
            if alphabetCounter < 11 then
              set a[charCounter] = "|cffFF0000"+a[charCounter]+"|r"
            endif
            if alphabetCounter > 10 and alphabetCounter < 37 then
              set a[charCounter] = "|cff00FF00"+a[charCounter]+"|r"
            endif
            if alphabetCounter > 36 and alphabetCounter < 63 then
              set a[charCounter] = "|cff0000FF"+a[charCounter]+"|r"
            endif
            if alphabetCounter >  62 then
              set a[charCounter] = "|cff00FFFF"+a[charCounter]+"|r"
            endif
            exitwhen true
          endif
          set alphabetCounter = alphabetCounter + 1
        endloop
        set Code = Code + a[charCounter]
        set charCounter = charCounter + 1
    endloop
    return Code
endfunction


Thanks for help. +rep
 
Reaction score
341
This would be the easier way of doing it..

JASS:
function SaveStringColor  takes string s returns string
    local integer i = StringLength(s)
    local string c
    local string r = ""
    loop
        set i = i - 1
        set c = SubString(s,i,i + 1)
        if c == "0" or c == "1" or c == "2" or c == "3" or c == "4" or c == "5" or c == "6" or c == "7" or c == "8" or c == "9" then
            set r = "YOURCOLOR" + c + "|r" + r
        elseif c == "a" or c == "b" or c == "c" or c == "d" or c == "e" or c == "f" or c == "g" or c == "h" or c == "i" or c == "j" or c == "k" or c == "l" or c == "m" or c == "n" or c == "o" or c == "p" or c == "q" or c == "r" or c == "s" or c == "t" or c == "u" or c == "v" or c == "w" or c == "x" or c == "y" or c == "z" then
            set r = "YOURCOLOR" + c + "|r" + r
        else
            set r = "YOURCOLOR"  + c + "|r" + r
        endif
        exitwhen i <= 0
    endloop
    return r
endfunction
 

ShadowInTheD

Active Member
Reaction score
12
But how to fix mine? (I'm stubborn!)

I found it, I forgot to set alphabetCounter back to zero when loop ended, but now I'm getting a new problem. It ate my $ and I don't know what happened to it (i.e. 23902ABDadaadfR29a032aSDF$adsADflkadf) and it just disappeared.

EDIT: Nvm, it's working perfectly fine.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top