Getting player names without joining room & displaying Lobby at all times

Options
Hi there.

In my game max 2 players can join a Room. My Lobby is a ScrollView with Buttons as Room Prefab.

In the Room Prefab(Button) I would like to show the Button Text as:
Vs

Each Room Prefab contains the Room Name, Size, Player Count but I can't get the list of Players without joining the Room.

People prefer finding a match in Lobby instead of challenging through Friends List. (There are other aspects of the game which you have to do alone so getting challenges from Friends all the time is not so pleasant)

Since its a 2 player game I don't want people to join each Room and check who is inside and instead show the player names in Prefab Text so they can choose a Room to play.
Is it possible to do so using the Room Name or custom properties or any way?

And I would also like to show the Lobby at all times because sometimes people just create new Rooms instead of joining others. So people can be able to leave and join other Rooms instead of getting isolated. (Apparently this does happen often)

Thank you

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Sourav,

    Is it possible to do so using the Room Name or custom properties or any way?


    The players' list is accessible only while joined to the room.
    For your use case, you can add one or two custom room properties visible to the lobby for player names.

    If you need only the room's creator's player name and it's guaranteed that player will remain in the room, you can hardcode it in the room name itself and parse it from it later.

    And I would also like to show the Lobby at all times because sometimes people just create new Rooms instead of joining others. So people can be able to leave and join other Rooms instead of getting isolated. (Apparently this does happen often)
    Read our "Matchmaking Checklist" carefully.
  • Sourav
    Sourav
    edited September 2019
    Options
    Hi @JohnTube , sorry for late response.

    I tried what you said and it is now working brilliantly and displaying the player Names. Thanks for the help.

    I have an issue with OnPhotonCustomRoomPropertiesChanged not being triggered.
    
    using Photon.Pun;
    using Photon.Realtime;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    using UnityEngine.UI;
    using System.Linq;
    using Assets.Scripts;
    using System.Data;
    using System;
    using System.Linq;
    using UnityEngine.EventSystems;
    
    public class GameController : MonoBehaviourPunCallbacks
    {
    void OnPhotonCustomRoomPropertiesChanged(ExitGames.Client.Photon.Hashtable propertiesThatChanged)
        {
            Debug.Log("OnPhotonCustomRoomPropertiesChanged triggered");
        }
    
    public void Draw()
        {
            List<Card> mydeck = AppData.StringToList((string)PhotonNetwork.CurrentRoom.CustomProperties["P1Deck"]);
            List<Card> myHand = AppData.StringToList((string)PhotonNetwork.CurrentRoom.CustomProperties["P1Hand"]);
    
               Card p1FirstCard = mydeck[0];
               mydeck.RemoveAt(0);
               myHand.Add(p1FirstCard);
    
               ExitGames.Client.Photon.Hashtable playerData = new ExitGames.Client.Photon.Hashtable();
    
               playerData .Add("P1Deck", AppData.ListToString(mydeck));
               playerData .Add("P1Hand", AppData.ListToString(myHand));
               PhotonNetwork.CurrentRoom.SetCustomProperties(playerNames2);
        }
    }
    
    SetCustomProperties is working fine, I can view the changes in my game but the method OnPhotonCustomRoomPropertiesChanged is never getting triggered.

    (Sorry the code is getting formatted into one line)
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @Sourav,

    The correct callback method name is OnRoomPropertiesUpdate.
    Besides extending MonoBehaviourPunCallbacks means that you need to override those callback methods.

    So:
    public void override OnRoomPropertiesUpdate(Hashtable hash)
    {
    }
  • Sourav
    Options
    Thank you @JohnTube ! Everything is working perfectly now :)