• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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]
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,464
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