Compressing Strings

Might be getting slight bug, not sure what I did when I fixed spacing:

Heres the script: Spectre

you changed line 17 to:
n = n or string.byte(c) - string.byte('a' + 10)
when it should be:
n = n or string.byte(c) - string.byte('a') + 10

you can call functions by passing just one string without having the parentheses: print'hello world' is the same as print('hello world')

Oh, I see, let me change it in the code

Edit: I never knew how to use those in code so I did my best guess to figure it out.

Edit 2:

I think the number is too big for the 50. (Since I’m going to be storing other data too) Is there any way to make it smaller? (and 100 player matches I guess are out of luck then)

1 Like

what exactly are you using the jobId for? is it only to check if two players in the same party server came from the same lobby server?

JobId is for if the server that hosts the matchmaking goes offline, then it will be auto transferred to a different server of a player in the lobby.

im not sure I understand
can you explain the entire system?

e.g:
are players starting in lobby servers
then there is a request to start a party
players in other servers are then teleported to one of the existing lobby servers?

Lobby is created / Player1 joins (and hosts since they created it)
Player2 joins
Player 3 joins
Player1 leaves and their server shuts down
Player3’s server is randomly chosen to handle matchmaking since the server shut down

I probably oversimplified the reason why I need the job id.

why cant you continue to use the lobby player1 created instead of going to a previous server (what kind of server) that may or may not still exist?
where do players join from?

It keeps the same lobby, it transfers the server controlling it though (for the timer etc.). And what I mean by server is the server you join.

i don’t understand at all xd
if you don’t want to re-use the server why not teleport everyone to a brand new server instead of a player’s old server? in that way you don’t need to store jobids

The matchmaking creates a “virtual” lobby via messaging service. Once the round starts, then they are teleported to a new server where the game actually happens. The players in a lobby could potentially be in different servers.

why does it matter which servers they originate from then if they are teleported to new servers anyways?

Since there needs to be a specific server to control the timer (like start timer when minimum players in game, then teleport them, etc.)

can each server not handle its own players?
use os.time() for a globally synced server time (utc)

There needs to be a specific server since each server wouldn’t generate the same access key. Also, I do use os.time() for the timer since I don’t send a message every second.

you can ReserveServer and pass the key initially, then each server can teleport to the private server when the time comes because according to the wiki “Access codes remain valid indefinitely, meaning reserved servers can still be joined if no game server is running (in this case a new game server will be started)”

so here it is with 100 players and just userid:

_G.reload()
local bitbuffer=_G.bitbuffer

local function serialize(plrs)
	local buff=bitbuffer.new()
	buff:ubyte(#plrs)
	
	for _,t in next,plrs do
		buff:ulong(t.userId)
	end
	return buff:ds()
end
local function deserialize(s)
	local buff=bitbuffer.ds(s)
	local plrs={}
	for i=1,buff:ubyte()do
		plrs[i]={
			userId=buff:ulong(),
		}
	end
	return plrs
end

local plrs={}
for i=1,100 do
	plrs[i]={userId=113926330,}
end
print(#serialize(plrs))
print(#_G.http:JSONEncode(plrs))

its 824 characters

i don’t think its that big of an overhead

1 Like

Yes, that could work, but I’d need to rewrite my code for the matchmaking to do that. Also, why create access codes when I’ll never end up using them? (Like if everyone leaves lobby)

Edit: I might implement that way instead, not sure yet. I should probably sleep as its 11:42 PM and think about it. Otherwise I’ll probably be up working on it till 1 AM (Which will probably happen)

Your idea is good though.

Edit 2: Doing your idea has a slight problem - each of the servers might not be in sync (they said there is like < 1 second delay) which could cause problems. I might just keep it below 50 players.

why is that a problem? they will all end up in the same server
anyways players take different amounts of time to teleport to you still need to account for variation if that was the issue (e.g: wait 30 seconds or until all players are in the game to start)

goodnight though if you are going to bed now

I slept on it and I think I might go with each server handling the timer, etc. separately like you said. The problem is, once I add map and gamemode voting I would need to switch back to the other method where there is a dedicated matchmaking server I think. (The reason is since all servers wouldn’t choose the same random map/gamemode — unless there is an algorithm I can use to make them choose the same random number based on a certain time, I do not know yet.) As for now, thanks for helping me compress the user ids so I can allow bigger lobbies.

to make them choose the same gamemode do use the Random with seed of your time: Random | Documentation - Roblox Creator Hub

local r=Random.new(startTime)
local mode=modes[r:NextInteger(1,#modes)]
1 Like