Warcraft III resources & community, 2003–2006 · archived

Char2AsciiKeyValue

not rated
Submitted by AltSubmitterFunctions0 downloads
Match the character to the correct integer used in the hotkey, string i.
This is an enhaced version of Data Angel's Ascii key finder function. It is more accurate and prevents soubling up (because the "UPPER" and "lower" cases are the same ASCII integer values in dalog hotkeys in the Warcraft III game.

Also for use with 2 other functions:
- DialogAddButtonWithLitkeyBJ / DialogAddButtonWithLitkeyColorBJ
- InsertHotkey / InsertHotkeyColor

Source

function Char2AsciiKeyValue takes string i returns integer
    local integer y = 0
    local integer r = 0
    local string s1 = "0123456789"
    local string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    local string s3 = "abcdefghijklmnopqrstuvwxyz"

    // s1 - check if it's a number
    loop
        set y = y + 1
        set r = y
        exitwhen ((y > 10) or (i == SubStringBJ(s1, y, y)))
    endloop
    if r <= 10 then
        set r = r + 47
        return r
    else
        set y = 0
        set r = 0
    endif

    if r == 0 then
        loop
            set y = y + 1
            set r = y
            exitwhen ((y > 26) or (i == SubStringBJ(s2, y, y)) or (i == SubStringBJ(s3, y, y)))
        endloop
    endif

    if ((r <= 26) and (r > 0)) then
        set r = r + 64
        return r
    endif

    return 0
endfunction

Comments

1
good work!