HashRegistry
Maps animation names to compact integer hashes for MotixNet.
HashRegistry is how animation names are serialized over the network without sending
full strings. Both server and client create a registry with the same names in the same
order. Each name gets an integer hash based on registration order. Intents carry only
the hash.
-- SharedAnimations.lua (required by both server and client, identical order)
local Motix = require(ReplicatedStorage.Motix)
local HashReg = Motix.MotixNet.HashRegistry.new()
HashReg:Register("Idle") -- hash 0
HashReg:Register("Walk") -- hash 1
HashReg:Register("Run") -- hash 2
HashReg:Register("Fire") -- hash 3
HashReg:Register("Reload") -- hash 4
return HashReg
Order is everything
Hash values are assigned sequentially by registration order. If the server registers
"Fire" before "Reload" and the client registers them in the opposite order, every
intent involving those animations will resolve to the wrong name. Require the same shared
ModuleScript on both sides and never register conditionally.
Functions
new
Creates a new empty HashRegistry.
local HashReg = Motix.MotixNet.HashRegistry.new()
Register
HashRegistry:Register(name: string--
The animation name to register.
) → number--
The integer hash for this name.
Registers an animation name and returns its hash.
If the name is already registered, the existing hash is returned without creating a
new entry. Hash values start at 0 and increment by 1 for each new registration.
local hash = HashReg:Register("Idle") -- returns 0 on first call
HashOf
HashRegistry:HashOf(name: string--
The animation name to look up.
) → number?--
The hash, or nil if not registered.
Returns the hash for a registered animation name, or nil if not registered.
local hash = HashReg:HashOf("Fire")
if hash then
-- use hash in a custom packet
end
NameOf
HashRegistry:NameOf(hash: number--
The integer hash to look up.
) → string?--
The animation name, or nil.
Returns the animation name for a hash, or nil if not found.
local animName = HashReg:NameOf(3)
if animName then
print(animName) -- "Fire"
end
IsRegistered
HashRegistry:IsRegistered(name: string--
The animation name to check.
) → booleanReturns whether the given animation name is registered.
if HashReg:IsRegistered("Grenade") then
-- safe to use in intents
end