[HELP] Photon Join Room

Options
miera
miera
Hi,
I tried to retrieve the room name from the code and appear it on the text so that when player want to join room they just can clicked on the text. However, I cannot get the room name.
public RoomInfo RoomInfo { get; private set; }
    
    public void SetRoomInfo(RoomInfo roomInfo)
    {
        RoomInfo = roomInfo;
        _text.text = roomInfo.MaxPlayers + ", " + roomInfo.Name;

        roomname = RoomInfo.Name;       
        
        Debug.Log("Room Name : " + roomname);
        
    }

    public void OnClick_Button()
    {
        //Debug.Log("Room Name : " + RoomInfo.Name);
        Debug.Log("Room Name : " + roomname);

        Debug.Log("Joining room in the list");
        PhotonNetwork.JoinRoom(roomname,null);
        Debug.Log("Room Listing Menu : Join Room");
    }
How can I get the room name in RoomInfo?

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @miera,

    Where do you get the roomInfo object from?
    What do you see in the logs?
  • miera
    miera
    edited October 2019
    Options
    public void OnClick_Button()
        {
            //Debug.Log("Room Name : " + RoomInfo.Name);
            <b class="Bold">Debug.Log("Room Name : " + roomname);</b>
    
            Debug.Log("Joining room in the list");
            PhotonNetwork.JoinRoom(roomname,null);
            Debug.Log("Room Listing Menu : Join Room");
        }
    The project cannot read the bold line when i tried to debug log it on console.
    The console show it like this.
    https://imgur.com/wtUK4fd


  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @miera,

    before calling OnClick_Button the roomname needs to be assigned.
    The roomname is assigned inside SetRoomInfo(RoomInfo roomInfo).

    When do you call SetRoomInfo and from where do you get the roomInfo variable you pass to it?
  • miera
    miera
    edited October 2019
    Options
    [SerializeField] 
        private RoomListing  _roomListing;
    - SetRoomInfo is in RoomListing.cs
     
    public override void OnRoomListUpdate(List<RoomInfo> roomList)
        {
            foreach (RoomInfo info  in roomList)
            {
                //remove from room list.
                if (info.RemovedFromList)
                {
                    int index = _listing.FindIndex(x => x.RoomInfo.Name == info.Name);
                    if(index != -1)
                    {
                        Destroy(_listing[index].gameObject);
                        _listing.RemoveAt(index);
                    }
                }
                //added rooms to list.
                else
                {
                    int index = _listing.FindIndex(x => x.RoomInfo.Name == info.Name);
                    if (index == -1)
                    {
                        RoomListing listing = <b class="Bold">Instantiate(_roomListing, _content);</b>
                        if (listing != null)
                        {
                            listing.SetRoomInfo(info);
                            _listing.Add(listing);
                        }
                    }
                }
            }
        }
    - SetRoomInfo will be instantiate when the player want to joined the room. It will display on the scroll view which room has been created.
    public void SetRoomInfo<b class="Bold">(RoomInfo roomInfo)</b>
        {
            RoomInfo = roomInfo;
            _text.text = roomInfo.MaxPlayers + " , " + roomInfo.Name;
    
            <b class="Bold">roomname = RoomInfo.Name;</b>
    
            Debug.Log("Room Name : " + roomname);
        }
    
    For your reference, here I attach my Github project link
    https://github.com/project-neuromender/SIP.git
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    The code looks OK.
    Somehow either:

    - RoomInfo.Name is null or empty initially
    or
    - RoomInfo.Name or roomname becomes null or empty at some point.

    I suggest you change:

    roomname = RoomInfo.Name;

    to

    roomname = roomInfo.Name;

    and retry.
  • miera
    Options
    I tried this but it still the same. Once public void OnClick_Button() is being call it can take the roomname = roomInfo.Name; as the variable are not being readable in public void OnClick_Button()