When using OOP i need to have unique IDs for each projectile, gun and ect., also i need to send it over the network
But if i do this
Remote:FireAllClients(self.ID)
And ID was generated by HTTP service, it would send 34 bytes over the network, which is huge, even using unreliable remote events wouldn’t help if i would send kilobytes of data over the network every frame, making game unplayable
Is there any alternative to HTTP service which doesn’t take that much memory? also doesn’t take a lot to store? any ideas?
You’re joking right? They’re called unreliable because they don’t do intensive checks to make sure the data gets to the other side which means some data may get dropped but it’s really perfomant
From inside the source code you can change the length of the UUID (by adding or removing the "x"s in the uuid function. This also has the advantage of checking if your UUID is actually unique, unline roblox GUID from HTTP Service.
I tried using numbers but i had to make active/inactive Id’s list, they took some space, let’s say 200 bullets were created at the same time, in this system they will be saved to a table, although if new bullets were made and those previous bullets were destroyed, it wouldn’t add any new registry, if let’s say someone fired a lot of bullets, tables will be crowded
you can use an 8-byte number which is really big (2^63 ig)
and if it’s a game with rounds you can reset the id to 0 and remove all the bullets after each round
and if it’s not you can remove all bullets once the id is 2^63 which is again a very big number
there might be better solutions that this, but this is what though of
-Server-
id = 0
new bullet:
set bullet.Id = id
Id += 1
if id == 2^63 then
reset id and send remote to client to remove all bullets
end
send(id)
-Client-
bullets = {}
onRecive(id):
local bullet Instance.new("Bullet")
extra stuff
bullets[id] = bullet
on update Position(id,Positon):
bullets[id].Positon = Position
onGameEndOrWhenIdIs 2^63:
remove all bullets from table
Using a buffer is a perfect solution. You can generate a UUID-sized buffer like this:
local function GenerateUUIDBuffer(): buffer
local UUIDRandom: Random = Random.new()
local UUIDBuffer: buffer = buffer.create(16)
local UUIDByte: number
for i=0, 15 do
UUIDByte = UUIDRandom:NextInteger(0, 255)
buffer.writeu8(UUIDBuffer, i, UUIDByte)
end
return UUIDBuffer
end
local function tostringUUIDBuffer(UUIDBuffer: buffer): string
local UUIDFormatString: string = "%.2x%.2x%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x"
local UUIDBytes: {number} = {}
local UUIDByte: number
for i=0, 15 do
UUIDByte = buffer.readu8(UUIDBuffer, i)
table.insert(UUIDBytes, UUIDByte)
end
return string.format(UUIDFormatString, table.unpack(UUIDBytes))
end