Hey! I hope your doing well, I am writing this because I need some help trying to figure out how to do this. I have been at this for a minute and I need some guidance.
Basically, in my project I have a network of remote events but 3 main ones
singleClient
allClient
serverReplicator
These events are used in many systems throughout my game and for my game to know what to fire I use identifiers. These are strings that I check if the identifier matches, if it does then I fire the code. These events fire a lot of times and I just came to the understanding about data sending along with Roblox Buffer system. I am mainly trying to figure out a way for me to compress my strings to be less bytes and then fire them across the server and client. I can decompress the string to detect the identifier after. Is there any good way to do this?
Rather than sending the ID as a string, you could send a number instead;
local event_names = {"Alpha", "Beta", "Gamma", "etc..."}
local event_id_lookup = {}
for id, name in eventNames do
event_id_lookup[name] = id
end
...
singleClient:FireClient( <player>, event_id_lookup.Alpha, foo, bar, etc, ... );
And on the receiving side you dispatch using the numeric IDs like you’re already doing with the string IDs.
If you don’t expect to have more than 200 or so events, a single byte for it is fine yes, but I can almost guarantee that optimizing your network usage that far is probably overkill (on Roblox at least!)
Just use a regular Lua[u] number and have practically unlimited number of event ID enumerators.
The most obvious one is LZW Compression. If you do some digging you should find a library for it on Roblox.
But if you want to compress more effectively, it strongly depends on the type of data you are sending. Bonus points if you design your own compression algorithm for your specific needs. Before turning your data into strings, you should first serialize it into a more efficient data format.
For example, if you wanted to store voxel data, instead of having a massive dictionary that stored each individual position, you could encode positions as base256 numbers (by utilizing extended ASCII) and group data by the type of block they represent.
--every 2 characters represent a voxel
{Grass="AABBCCDDEEFFGG", Stone="HHIIJJKKIIMMNN"}
Or it could be greedymeshed and you have two positions that represents each cuboid of blocks.
--every 4-character element defines a cuboid by storing its corner positions
{Grass={"AABB", "CCDD", "EEFF"}}
Or instead of using strings, you could use buffers and different integer formats: