Another question is, when a new player joins, they dont have the most updated information for players joined before him, related to the same issue of just fetching players.
Also, I see again that playerDataAdded and playerDataChanged dont trigger sometimes even after that enable trick.
Edit: I solved my issue, it was my lack of understanding.
For the callbacks not being triggered, you need to assign callbacks before registering for events. Such as:
callbacks.PlayerJoined += (List<LobbyPlayerJoined> lobbyPlayerJoined) => { TryPollLobby("player joined"); };
callbacks.PlayerLeft += (List<int> leftPlayers) => { TryPollLobby("player left"); };
await LobbyService.Instance.SubscribeToLobbyEventsAsync(id, callbacks);
Instead of:
await LobbyService.Instance.SubscribeToLobbyEventsAsync(id, callbacks);
callbacks.PlayerJoined += (List<LobbyPlayerJoined> lobbyPlayerJoined) => { TryPollLobby("player joined"); };
callbacks.PlayerLeft += (List<int> leftPlayers) => { TryPollLobby("player left"); };
For the other issue, the lobby actually has the player data, but I was doing an incorrect iteration to get the data. Here is a working example.
public void UpdatePlayerList()
{
var thisPlayerId = AuthenticationService.Instance.PlayerId;
foreach (var player in lobby.Players)
{
var playerName = player.Id;
var playerId = player.Id;
var colorIndex = 0;
var teamIndex = 0;
var isReady = false;
if (player.Data != default)
{
foreach (var key in player.Data.Keys)
{
var value = player.Data[key];
switch (key)
{
case GameDataHandler.KEY_LOBBY_PLAYER_DATA_NAME:
playerName = value.Value;
break;
case GameDataHandler.KEY_LOBBY_PLAYER_DATA_COLOR:
colorIndex = Convert.ToInt32(value.Value);
break;
case GameDataHandler.KEY_LOBBY_PLAYER_DATA_TEAM:
teamIndex = Convert.ToInt32(value.Value);
break;
case GameDataHandler.KEY_LOBBY_PLAYER_DATA_READY:
isReady = value.Value == "1" ? true : false;
break;
default:
break;
}
}
}
var isHost = lobby.HostId == playerId;
var isOwner = thisPlayerId == playerId;
}
}
The confusion was trying to update the lobby by getting pieces of information on callbacks. My solution was to subscribe to every event to trigger a lobby poll, but also since there is a rate limit, it only registers a function to be called in 1.1 seconds, if there is another lobby poll request, it cancels the request scheduled previously and schedules a new one. This way the most frequent call is always 1.1 seconds, which is lower than the rate limit of 1 request per second.
I don’t know how to contribute to docs but definitely the docs need more clarification.
Hopefully this helps somebody.