Problem with getting a line of code written for PUN 1 to work with PUN 2

Hi all,
While following a YouTube video on setting up a chatroom I came across this line of code written for Pun 1.X:

this.chatClient.Connect (PhotonNetwork.PhotonServerSettings.ChatAppID, "anything", new ExitGames.Client.Photon.Chat.AuthenticationValues(plrName.text));

As I have version 2 on my computer i am getting a message warning that "Chat" is not part of the namespace and it is stopping my code from compiling.

I checked the documentation and tried this quick and dirty fix:

this.chatClient.Connect(PhotonNetwork.PhotonServerSettings.ChatAppID, "anything", new AuthenticationValues(plrName.text));

But it''s obviously a bit too quick and dirty, and I am missing something (or many things) out here. Can someone who's been there help me out of this? Everything else seems OK, and I just need to fix this "minor" issue.

Thanks in advance.



Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @legrandtimonier1951,

    Thank you for choosing Photon!

    Try replacing ExitGames.Client.Photon.Chat.AuthenticationValues with Photon.Chat.AuthenticationValues.
  • Thx for getting back to me on this. Will try and post results here.

    Regards
  • Yep, your suggestion did fix that problem. There is one other one perhaps you might help me with. In the version of Unity that was being used there was an auto-lobby creation check box that could be clicked, whereas with 2017.2.17 this feature has been removed. any tip on how I can do what one used to be able to do in this regard in the latest greatest version of Unity?
  • I am getting close, I think, to getting a connection, but still no cigar. Can someone tell me what's wrong with the following line of code:

    chatClient.Connect(PhotonNetwork.PhotonServerSettings.ChatAppID, "anything", new Photon.Chat.AuthenticationValues(plrName.text));

    I see my Debug.Log("Trying to connect...") telling me things have got this far, but that's where the script gets stuck and I don't get a connection established. Is there anything obviously wrong with this line of code?
  • legrandtimonier1951
    edited November 2018
    Happened on the PUN Chat Demo. Seems that looking under the hood of the ChatGUI.cs file and perhaps other places and imitating what I see is the best way to avoid knocking my head against the wall. I already have a basic quick and dirty low-level API Unity chat system that runs on my CentOS server, but I'd prefer to move to Photon's way of doing business. I just don't want to spend the rest of my life getting there. If anyone has any docs to point me to (besides the basic tips in the Photon Chat Intro doc on the Photon site) please let me know. Saw a couple of YouTube videos (in French, where everything always sounds better), but they dealt with the previous version of the PUN Chat Demo, so not of much use. (The Scripts file is no longer in the latest greatest version of the demo).
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited November 2018
    Hi @legrandtimonier1951,

    You are asking different things and what you are asking is not very clear.
    The Auto-JoinLobby feature is off topic here and was asked elsewhere on the forum and is available on the "Migration Notes": in PUN2 you simply need to manually join a lobby once connected.

    The Chat thing, maybe you are mixing Photon Chat and the Photon Chat that comes with PUN2.
    PUN2 includes a new version of Photon Chat, let's call it Photon Chat 2 that is not released elsewhere and maybe the documentation wasn't updated also.
    If you have two different PhotonChatApi folders in your assets you need to clean up.
    PUN2 includes Photon Chat already, everything Photon related should be under "Assets\Photon" only.
    Maybe you've missed it but the ChatDemo is not under "PhotonUnityNetworking/Demos" but under "PhotonChat/Demos".

    I don't get a connection established
    Did you implement the OnConnected callback from IChatClientListener?
  • Pardon me for not being clear here.

    No, I have a clean version of "PUN Chat 2" on my computer imported from PUN 2 (Free version). I saw the warning in the Free PUN Chat asset so I didn't download it. So my setup is clean, but I was watching a video where I noticed a guy clicking on an "Auto-connect to Lobby" button that I don't have in my version of Photon. It was in this same video that I saw the reference to "...Chat..." in the code line:

    this.chatClient.Connect (PhotonNetwork.PhotonServerSettings.ChatAppID, "anything", new ExitGames.Client.Photon.Chat.AuthenticationValues(plrName.text));

    At that point I tried your code rewrite suggestion, which worked in that line, but later in the same program I discovered other things that didn't compile. So I dropped that series of videos and fired up "PUN Chat 2" in the Demo Hub of PUN 2 - Free Version and started looking long and hard at the code of ChatGUI. I also checked out a long French video that used what you might call the old "PUN Chat 1" that has a Scripts file that can be copied and tweaked to adapt to a particular user's needs. But since PUN Chat 2 doesn't have this file I have decided go back to the series of videos with the code you were kind enough to suggest a fix for and re-follow the steps of that working Photon PUN chat system (at least in the version the guy in the video's build) to see if I can tweak/rewrite any of his now deprecated code lines to make them work with Photon PUN 2.
  • legrandtimonier1951
    edited December 2018
    Emerging from the engine room, so to speak, I have a problem with the message I keep getting when trying to run the first part of my chat.cs program attached to the Main camera, as per the video I've been following. A Debug.Log message in my script keeps telling me "No Chat ID provided" even though I went to the dashboard and copied my App ID Chat from Photon and stuck it in the right field in the PhotoServerSettings. At least I think I did. I also put the App ID Realtime in its field as I assume I must, otherwise I get a message telling me to run the Wizard. Anyone have an idea what might be going wrong here? Here is the part of my code that fails to get me connected:

    void Start () {
    Application.runInBackground = true;
    if (string.IsNullOrEmpty(PhotonNetwork.PhotonServerSettings.ChatAppID))
    {
    print("No Chat ID provided.");
    return;
    }
  • Just happened on the PUN 2.5 reference manual, which I'd been looking for for a few days. I see now that it's useless trying to get this to work without RTFM.
  • legrandtimonier1951
    edited December 2018
    Can anyone tell me what's wrong with this code:

    void Start () {
    Application.runInBackground = true;
    if (string.IsNullOrEmpty(PhotonNetwork.PhotonServerSettings.appId))
    {
    print("No Chat ID provided.");
    return;
    }
    connectionState.text = "Connecting...";
    worldChat = "world";
    getConnected();
    }
    // Update is called once per frame
    void Update () {

    this.chatClient.Service();
    }

    void getConnected()
    {
    print("Trying to connect...");
    this.chatClient = new ChatClient(this);
    this.chatClient.Connect (PhotonNetwork.PhotonServerSettings.appId, "anything", new Photon.Chat.AuthenticationValues (plrName.text));
    connectionState.text = "Connecting to chat.";
    }



    I RTFM-ed, the relevant parts of the PUN 2.5 reference, found that appId was what I should use instead of what I was using, but still no joy. I got the Chat App ID aftter creating a chat application in the Chat section of Dashboard and put it in the right field of PhotonServerSettings.
  • JohnTube
    JohnTube ✭✭✭✭✭
    replace
    PhotonNetwork.PhotonServerSettings.appId
    with
    PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat