I need the displayName field in the player collection to be unique, meaning no 2 players will have the same displayName.
What I thought about doing is to have this cloud code in the ChangeUserDetails script:
Spark.getData().displayName;
if (displayName) {
var query = {"\"displayName\"" : "\"" + displayName + "\""};
var result = Spark.find("player", query);
var playerNameFound = (result.length() > 0);
if (playerNameFound)
throw "ERROR_NAME_TAKEN";
}
However no matter what I tried, result was always empty, even if the queried displayName exists in the player collection.
If it is indeed unqueriable, what is an alternative to verifying no 2 player will have the same displayName?
Thanks
Nitay
Best Answer
C
Customer Support
said
about 6 years ago
Hey Nitay,
I thought that might be the case, just wanted to check :)
So, in order to make sure of unique displayNames, you will need to keep a record of your own players as they register the displayName. To achieve this, you can add some code into the ChangeUserDetailsRequest which will check for the displayName in a custom collection. If the name exists, then you can call Spark.exit() to force the request to stop. If the name is not in the collection you can add it.
This is handy because you can also use this collection to store additional player info when you need it.
Let me know if that makes sense or if you need any further help.
The player collection is a system-collection so we dont give access to this collection as editing it could cause critical-errors in your game config.
However, the userName field (used when you register a user) is unique so you could use that unless there is some reason you cannot. Please let us know.
Thanks, Sean
N
Nitay Megides
said
about 6 years ago
Hi Sean,
Thanks for the info.
If I understand correctly in order to use the userName field the player must authenticate with a password. I'm currently using device authentication to lower registration friction for my players.
That's why I've wanted to use displayName, which is chosen by the user, as a unique name for each player.
Is there a way to do so?
Thanks
Nitay
Customer Support
said
about 6 years ago
Answer
Hey Nitay,
I thought that might be the case, just wanted to check :)
So, in order to make sure of unique displayNames, you will need to keep a record of your own players as they register the displayName. To achieve this, you can add some code into the ChangeUserDetailsRequest which will check for the displayName in a custom collection. If the name exists, then you can call Spark.exit() to force the request to stop. If the name is not in the collection you can add it.
This is handy because you can also use this collection to store additional player info when you need it.
Let me know if that makes sense or if you need any further help.
Nitay Megides
Hi,
I need the displayName field in the player collection to be unique, meaning no 2 players will have the same displayName.
What I thought about doing is to have this cloud code in the ChangeUserDetails script:
However no matter what I tried, result was always empty, even if the queried displayName exists in the player collection.
https://support.gamesparks.net/support/discussions/topics/1000074284This post says that the 'player' collection is "unqueriable". Is that correct? Where can I find this in the documentation.
If it is indeed unqueriable, what is an alternative to verifying no 2 player will have the same displayName?
Thanks
Nitay
I thought that might be the case, just wanted to check :)
So, in order to make sure of unique displayNames, you will need to keep a record of your own players as they register the displayName.
To achieve this, you can add some code into the ChangeUserDetailsRequest which will check for the displayName in a custom collection.
If the name exists, then you can call Spark.exit() to force the request to stop.
If the name is not in the collection you can add it.
This is handy because you can also use this collection to store additional player info when you need it.
Let me know if that makes sense or if you need any further help.
Thanks,
Sean
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hey Nitay,
The player collection is a system-collection so we dont give access to this collection as editing it could cause critical-errors in your game config.
However, the userName field (used when you register a user) is unique so you could use that unless there is some reason you cannot.
Please let us know.
Thanks,
Sean
Nitay Megides
Hi Sean,
Thanks for the info.
If I understand correctly in order to use the userName field the player must authenticate with a password. I'm currently using device authentication to lower registration friction for my players.
That's why I've wanted to use displayName, which is chosen by the user, as a unique name for each player.
Is there a way to do so?
Thanks
Nitay
Customer Support
I thought that might be the case, just wanted to check :)
So, in order to make sure of unique displayNames, you will need to keep a record of your own players as they register the displayName.
To achieve this, you can add some code into the ChangeUserDetailsRequest which will check for the displayName in a custom collection.
If the name exists, then you can call Spark.exit() to force the request to stop.
If the name is not in the collection you can add it.
This is handy because you can also use this collection to store additional player info when you need it.
Let me know if that makes sense or if you need any further help.
Thanks,
Sean
Nitay Megides
Okay, will try that - Thanks!
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics