I would like to set some script data values when a new user is created. I thought to do this by seeing if private data contains the key Initialized or something like that when a DeviceRegistrationRequest happens in cloud code, but I get an error that this cannot be done because private data is null. I suppose I could make sure and set a different key in private data before hand no matter what but that seems rather hacky. What is the proper way to go about checking if the player is newly created?
The way to do this would be in the AuthenticationResponse. In the Cloud Code you can check if the user has a key called "Registered", if they don't it must be a new user and set the scriptData "Registered" to true.
Then if a user who logs in checks if Registered is there they must be a returning user.
if(Spark.getScriptData("Registered")=== null) {
//Do the new user stuff
Spark.setScriptData("Registered", true);
}
if(Spark.getScriptData("Registered"=== true)){
//Do returning user stuff
}
I would like to note that if you are using Unity you wont be able to access any data stored in Private Data, this information is only usable in Cloud Code. To use information in Unity please use ScriptData.
James Peebles
I would like to set some script data values when a new user is created. I thought to do this by seeing if private data contains the key Initialized or something like that when a DeviceRegistrationRequest happens in cloud code, but I get an error that this cannot be done because private data is null. I suppose I could make sure and set a different key in private data before hand no matter what but that seems rather hacky. What is the proper way to go about checking if the player is newly created?
Okay got it working, thanks. I think you meant
though
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi James,
The way to do this would be in the AuthenticationResponse. In the Cloud Code you can check if the user has a key called "Registered", if they don't it must be a new user and set the scriptData "Registered" to true.
Then if a user who logs in checks if Registered is there they must be a returning user.
I would like to note that if you are using Unity you wont be able to access any data stored in Private Data, this information is only usable in Cloud Code. To use information in Unity please use ScriptData.
Shane
James Peebles
Okay got it working, thanks. I think you meant
though
Customer Support
Yes, you are correct, sorry about that! Glad to hear that it's working
Shane
Prom Rithy
On AuthenticationResponse cloud code
if(Spark.getData().newPlayer === true) {
//Do the new user stuff
} else {
//Do returning user stuff
}
1 person likes this
-
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