GetHashKey Returning Wrong Values?

Does anyone know why when I call GetHashKey( “WEAPON_ASSAULTRIFLE” ) it returns -1074790457 instead of 3220176749? This happens as well with other hash keys and it’s quite strange.

If those numbers are accurate, that’s a major bug.

Odds are you’re just using inconsistent data types. 3220176749 is the unsigned 32 bit representation of 0xBFEFFF6D and -1074790547 is the signed 32 bit representation. If the 5 and 4 are actually swapped though…

Depending on language, fixing it could be a simple cast or it could require conditioning against 2^(31) or 0 and adding/subtracting 2^(32). Javascript hates unsigned ints by the way.

1 Like

Those numbers are what are printed to the console when I use GetHashKey in a for loop on the following table:

local assaultRifles =  -- we'll just test the assault rifles first
{
    "WEAPON_ASSAULTRIFLE",
    "WEAPON_CARBINERIFLE", 
    "WEAPON_ADVANCEDRIFLE", 
    "WEAPON_BULLPUPRIFLE",
    "WEAPON_SPECIALCARBINE"
}

The only item in that table that returns the correct value is WEAPON_BULLPUPRIFLE.

If so, you better directly use the hexa number corresponding to your item list

are you sure of that and did you not typo the number? if you did typo, it’s perfectly normal as the native ABI specifies returned integers are signed, and won’t change a thing.

Are you sure? Did you copy and paste? roe is saying that the native returns a signed int, and the number you are expecting is too large to be a signed 32bit value. No one cares if you accidentally swapped two digits in a 10 digit number.

Dumping those strings into my personally coded Javascript Jenkins hasher results in
-1074790547=joaat(“WEAPON_ASSAULTRIFLE”)
-2084633992=joaat(“WEAPON_CARBINERIFLE”)
-1357824103=joaat(“WEAPON_ADVANCEDRIFLE”)
2132975508=joaat(“WEAPON_BULLPUPRIFLE”)
-1063057011=joaat(“WEAPON_SPECIALCARBINE”)

As you can see, only one of those is a positive value (i.e. it would equal the value cast to unsigned.) If you want the unsigned values, add 2^(32) = 4294967296 to the ones that are negative.

I’ll do some more testing with my script and see if I can figure out what I’m doing wrong based on what you all suggested, thanks!

6 Years later and still helped me Thanks!