• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Lua][vJass] Ascii

Of course, be warned, StringHash returns very large values, usually between a few hundred millions and a 2.1 billion, and often very small like -1.9 billion or something, so they are not siutable for array use.
Of course, here, Ascii takes the StringHash value, and minimizes it using division (dividing by something around 0x40000) and then adds a value to range it from 0 to 8192.

I'd only recommend using StringHash for hashtable keys.
You can however use my StringIndexer to get a unique id for each string that is in the range [0....8191]
 
If anyone wants a Lua version of this exact API for backwards-compatibility, here it is in all its glory:

Lua:
Char2Ascii = string.byte
Ascii2Char = string.char
function A2S(value)
    local result = ""
    for byteno=1,4 do
        result = string.char(value % 256) .. result
        value = value // 256
    end
    return result
end
S2A = FourCC
 
Top