Warp/src/Index/Util/Serdes.luau

23 lines
728 B
Lua
Raw Normal View History

2024-01-05 12:14:38 +00:00
--!strict
local RunService = game:GetService("RunService")
local SerInt = 0
local Event = require(script.Parent.Parent.Event).Reliable
local Assert = require(script.Parent.Assert)
2024-03-18 05:50:04 +00:00
return function(Identifier: string): number
2024-01-05 12:14:38 +00:00
Assert(typeof(Identifier) == "string", "Identifier must be a string type.")
Assert(SerInt < 255, "reached max 255 identifiers.")
if RunService:IsServer() then
if not Event:GetAttribute(Identifier) then
SerInt += 1
2024-03-13 01:01:27 +00:00
Event:SetAttribute(Identifier, SerInt)
--Event:SetAttribute(Identifier, string.pack("I1", SerInt)) -- I1 -> 255 max, I2 -> ~ 6.5e4 max. (SerInt)
2024-01-05 12:14:38 +00:00
end
else
while not Event:GetAttribute(Identifier) do
task.wait(0.5)
end
end
return Event:GetAttribute(Identifier)
end