Rom name generation
Options
Hi,
I want to get a custom naming system which will have two characteristics:
Second idea was to have a server that issue name, but Ido not like this.
I do not know if photon has any builtin mechanism for customizing room name, so please if there is any let me know.
I want to get a custom naming system which will have two characteristics:
- Length of room name is 4 characters
- It has only Upper or lower case characters
Second idea was to have a server that issue name, but Ido not like this.
I do not know if photon has any builtin mechanism for customizing room name, so please if there is any let me know.
0
Comments
-
Any help on this please?0
-
why only 4 chars?
0 -
because the players can read the code and enter. I can extend this, but first I need an approach how to solve it.0
-
Hi @Eduard,
I guess the name should be randomly generated, shouldn't it? If so you can use Unity's Random functionality in order to create a 'random' number between 65 and 90 (uppercase characters) or 97 and 122 (lowercase characters), take a look at the ASCII table for more information. Then you can cast this number to a char and furthermore append this char to a string. In code this might look like the following:public void CreateRandomName() { string name = ""; for (int counter = 1; counter <= 4; ++counter) { bool upperCase = (Random.Range(0, 2) == 1); int rand = 0; if (upperCase) { rand = Random.Range(65, 91); } else { rand = Random.Range(97, 123); } name += (char)rand; } Debug.Log(name); }
0 -
Hi @Christian_Simon.
Yes name should be randomly generated. But if we generate it in unity we need to compare it again all other room names. At as the number of rooms increases I guess that the chance that generated string will not be unique, so there are a lot of for loops.
I hope someone from photon technical support will comment here to see this approach:
Like Christian said we generate string then we try to create room. if oncreateroomfailed is called then we repeat again. What are drawbacks of this?0 -
When using this approach you have 52^4 different possibilities for the name which is a lot. So I guess it will take some time until you really got an already existing name. If this happens anyway you already have OnCreateRoomFailed callback to re-run the procedure and as far as I would say there is no problem with running this procedure even up to five times which is an absolutely worst case scenario.1
-
@Eduard FYI:I hope someone from photon technical support will comment here to see this approach
my colleague @Christian_Simon is the best "someone from photon technical support".2 -
ok thank you both for your help.0