#Thread to not flil this with my code xD
1 messages · Page 1 of 1 (latest)
public async void CreateRoom()
{
// Check if player is in a lobby already, if so quit it
RoomFound = false;
try
{
var options = new SessionOptions
{
MaxPlayers = 2
}.WithRelayNetwork();
var session = await MultiplayerService.Instance.CreateSessionAsync(options);
RoomFound = true;
session.CurrentPlayer.SetProperty("PlayerName", new(AuthenticationManager.Instance.PlayerName()));
session.PlayerJoined += OnPlayerConnected;
await session.SaveCurrentPlayerDataAsync();
_hostNameText.text = AuthenticationManager.Instance.PlayerName();
_lobbyRoomCodeText.text = session.Code;
_currentSession = session;
}
catch (SessionException e)
{
Debug.Log(e);
}
}
public async void JoinRoom(string roomCode)
{
RoomFound = false;
try
{
var session = await MultiplayerService.Instance.JoinSessionByCodeAsync(roomCode);
RoomFound = true;
session.CurrentPlayer.SetProperty("PlayerName", new(AuthenticationManager.Instance.PlayerName()));
await session.SaveCurrentPlayerDataAsync();
_guestNameText.text = AuthenticationManager.Instance.PlayerName();
_lobbyRoomCodeText.text = session.Code;
_currentSession = session;
session.PlayerJoined += OnPlayerConnected;
}
catch (SessionException e)
{
Debug.Log(e);
}
}
void OnPlayerConnected(string obj)
{
Debug.Log("OnPlayerConnected is being callled");
foreach (var player in _currentSession.Players)
{
var playerName = player.Properties["PlayerName"].Value;
if (_currentSession.Host == player.Id)
_hostNameText.text = playerName;
else
_guestNameText.text = playerName;
}
on the joined player, both names are visible now
however for the Host, nothing changes
public async void CreateRoom()
{
// Check if player is in a lobby already, if so quit it
RoomFound = false;
try
{
var options = new SessionOptions
{
MaxPlayers = 2
}.WithRelayNetwork();
var session = await MultiplayerService.Instance.CreateSessionAsync(options);
RoomFound = true;
session.CurrentPlayer.SetProperty("PlayerName", new(AuthenticationManager.Instance.PlayerName()));
await session.SaveCurrentPlayerDataAsync();
session.PlayerJoined += OnPlayerConnected;
_hostNameText.text = AuthenticationManager.Instance.PlayerName();
_lobbyRoomCodeText.text = session.Code;
OnPlayerConnected("-Host- Player Connected");
_currentSession = session;
}
catch (SessionException e)
{
Debug.Log(e);
}
}
public async void JoinRoom(string roomCode)
{
RoomFound = false;
try
{
var session = await MultiplayerService.Instance.JoinSessionByCodeAsync(roomCode);
RoomFound = true;
session.CurrentPlayer.SetProperty("PlayerName", new(AuthenticationManager.Instance.PlayerName()));
await session.SaveCurrentPlayerDataAsync();
_guestNameText.text = AuthenticationManager.Instance.PlayerName();
_lobbyRoomCodeText.text = session.Code;
_currentSession = session;
session.PlayerJoined += OnPlayerConnected;
OnPlayerConnected("Player Connected");
}
catch (SessionException e)
{
Debug.Log(e);
}
}
void OnPlayerConnected(string obj)
{
Debug.Log("OnPlayerConnected is being callled");
foreach (var player in _currentSession.Players)
{
var playerName = player.Properties["PlayerName"].Value;
if (_currentSession.Host == player.Id)
_hostNameText.text = playerName;
else
_guestNameText.text = playerName;
}
}```
I think its because you are setting the 2nd player name after they join. the PlayerPropertiesChanged event is what you would need there
welp
session.PlayerPropertiesChanged += UpdateNames;```
also tried this but
what should it return? XD
It should just be void and not Event
oh wtf
why did it work but not the other xD
thanks
... hmm
well
it works for the build (client), but not the host (unity in this case)
public async void CreateRoom()
{
// Check if player is in a lobby already, if so quit it
RoomFound = false;
try
{
var options = new SessionOptions
{
MaxPlayers = 2
}.WithRelayNetwork();
var session = await MultiplayerService.Instance.CreateSessionAsync(options);
RoomFound = true;
_currentSession = session;
session.PlayerPropertiesChanged += UpdateNames;
session.CurrentPlayer.SetProperty("PlayerName", new(AuthenticationManager.Instance.PlayerName()));
await session.SaveCurrentPlayerDataAsync();
_hostNameText.text = AuthenticationManager.Instance.PlayerName();
_lobbyRoomCodeText.text = session.Code;
}
catch (SessionException e)
{
Debug.Log(e);
}
}
public async void JoinRoom(string roomCode)
{
RoomFound = false;
try
{
var session = await MultiplayerService.Instance.JoinSessionByCodeAsync(roomCode);
RoomFound = true;
_currentSession = session;
session.PlayerPropertiesChanged += UpdateNames;
session.CurrentPlayer.SetProperty("PlayerName", new(AuthenticationManager.Instance.PlayerName()));
await session.SaveCurrentPlayerDataAsync();
_guestNameText.text = AuthenticationManager.Instance.PlayerName();
_lobbyRoomCodeText.text = session.Code;
}
catch (SessionException e)
{
Debug.Log(e);
}
}
void UpdateNames()
{
foreach (var player in _currentSession.Players)
{
var playerName = player.Properties["PlayerName"].Value;
var playerId = player.Id;
if (playerName != null)
{
if (_currentSession.Host == playerId)
_hostNameText.text = playerName;
else
_guestNameText.text = playerName;
}
else
{
Debug.Log("No name found for this player.");
}
}
}```
I wonder what the heck I'm doing wrong 😦
wonder how I would suscribe the host players to it
also
how do you know so much Evilotaku? XD
if there's barely any documentation or source of information about it
I'm so lost it just makes me sad
I assume this is happening because, the property is being changed
however it is saved after the change
so that's probably why, it's called but saved after