Photon nicknames and chat

Hello!
I use PUN and DB in my game.
I parse nicknames from DB via PHP, and write values in variable “namechar”.
After I replaced value “PhotonNetwork.playerName”.

PhotonNetwork.playerName = namechar;

Then I write this in my chat script.

AddMessage(PhotonNetwork.playerName + ": " + text);

In this line somehow playerName == “”
And I use variable from menu script:

AddMessage(MainMenu.namechar + ": " + text);

If I use this that different players have one nickname.

Please help me decide this problem.
P.S. Sorry me for my bad english

I am not aware of a bug that will reset the playerName to “”. It might be in your code or something I didn’t notice yet.
You should check all usages of PhotonNetwork.playerName and see if you set it in some code that might run more than once (Start(), Awake() or similar).

Are you using the latest PUN version 1.25?

I already check all use of PhotonNetwork.playerName and nothing found.
I use 1.0.

Please refer to PhotonNetwork.versionPUN for your current PUN version. v1.0 would be really old.

Ok.
I fully tested to get the values ​​of PHP, it turned out that the values ​​are not empty only within IEnumerator. Here’s the code IEnumerator and variables.

	public static string namechar;
	public static string goldchar;
	public static string hpchar;
	public static string mpchar;
	public static float xpos;
	public static float ypos;
	public static float zpos;
	public static string acc_id;
	public static string char_id;

        IEnumerator HandleLogin(string login, string password) {

        WWWForm form = new WWWForm();
        form.AddField("mylogin", login);
        form.AddField("mypassword", password);
        WWW Login = new WWW(url, form);
        yield return Login;
        
        string a = Login.text;       //get echo from php
	string[] all = a.Split('|');
	namechar = all[1];
	goldchar = all[2];
	hpchar = all[3];
	mpchar = all[4];
	xpos = float.Parse(all[5]);
	ypos = float.Parse(all[6]);
	zpos = float.Parse(all[7]);
	acc_id = all[8];
	char_id = all[9];
	print(a);

	if (all[0] == "Ok") {
		LogIn = false;
		chooseChar = true;
		}
	}

I think I understood why PhotonNetwork.playerName variable to the empty string. The fact that the variable PhotonNetwork.playerName created before the database will record data in a variable after entering the username and password. It remains to understand how to fix it.

I fixed it by moving “PhotonNetwork.playerName = namechar;” in Update.
Now displayed nickname someone who stands in the first table in the DB.

This sounds like you found a solution. Very good.

You might want to take a look at Photon’s “Custom Authentication” feature. It allows you to use Photon API to authenticate a user and will encrypt username and password from client to server.
More about that:

On the other hand: As this is working for you now, there is no need to change a running system :slight_smile: