Warcraft III resources & community, 2003–2006 · archived

AsciiCharToInteger

not rated
Submitted by PepparVariable Change0 downloads
Returns the Ascii value of the first character in string char.

I'm not entirely certain that the \-references are correct.

This is the counter-function to AsciiIntegerToChar.

AsciiCharToInteger("A") = 65
AsciiCharToInteger("BC") = 66
AsciiCharToInteger("!") = 33

NOTE! You MUST place this function in the map root custom script section in the trigger editor. If you want to place this function somewhere else, replace the first line in the function with this:

local string charMap = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

Source

function AsciiCharToInteger takes string char returns integer
    local string charMap = " !\"#$%%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
    local string u = SubString(char, 0, 1)
    local string c
    local integer i = 0
    if u == "" or u == null then
        return 0
    elseif u == "\b" then // Backspace?
        return 8
    elseif u == "\t" then // Horizontal Tab?
        return 9
    elseif u == "\n" then // Newline
        return 10
    elseif u == "\f" then // Form feed?
        return 12
    elseif u == "\r" then // Carriage return
        return 13
    endif
    loop
        set c = SubString(charMap, i, i + 1)
        exitwhen c == ""
        if c == u then
            return i + 32
        endif
        set i = i + 1
    endloop
    return 0
endfunction

Comments

0

No comments.