GSRequestData emailData = new GSRequestData();
emailData.AddString("email", email.text);
new GameSparks.Api.Requests.RegistrationRequest()
.SetUserName(userName.text)
.SetPassword(password.text)
.SetDisplayName(displayName.text)
.SetScriptData(emailData)
.Send((response) => {
if (!response.HasErrors)
{
}
}
);
And in cloud code i want to get the data from emailData and set it to player script;
var emailData = Spark.getData().email;
//Set email to the player script
Spark.getPlayer().setScriptData("email", emailData);
The problem is that Spark.getData().email return undefined.
I Also tried other ways like Spark.getPlayer().getScriptData("email") or Spark.getData(),email and other similar but it never works, it crashes or returns nul/undefined...
Any solution?
Best Answer
C
Customer Support
said
over 4 years ago
Hi Adriá,
Is your cloud code in your RegistrationRequest or RegistrationResponse?
If it's in registration request, your player won't have been created yet, so you won't be able to set data on it.
If it's in registration response, you'll need to pass the scriptData supplied to your RegistrationRequest on to your RegistrationResponse in order to use it. Like so:
Have you been able to reproduce this inside the Test Harness? You can attach scriptData to your registrationRequest inside the Test Harness JSON builder.
After this, I would do a log on all the data coming in from the client to RegistrationRequest.
You can check this log in the script.log collection to see exactly what data came in. Of course, using the Test Harness you can also do this, with a trace of how your variables are changing over time.
Let me know if this helps you in diagnosing your bug further,
Pádraig
A
Adrià Martín
said
over 4 years ago
I added the scriptData in the test harness and made some test.
Using Spark.getLog().debug(JSON.stringfy(Spark.getData())); on the log i can see that the data from scriptData is not received... that's why the Spark.getData() in RegistrationResponse always return null or undefined.
Customer Support
said
over 4 years ago
Answer
Hi Adriá,
Is your cloud code in your RegistrationRequest or RegistrationResponse?
If it's in registration request, your player won't have been created yet, so you won't be able to set data on it.
If it's in registration response, you'll need to pass the scriptData supplied to your RegistrationRequest on to your RegistrationResponse in order to use it. Like so:
Adrià Martín
In unity i call registerRequest:
And in cloud code i want to get the data from emailData and set it to player script;
The problem is that Spark.getData().email return undefined.
I Also tried other ways like Spark.getPlayer().getScriptData("email") or Spark.getData(),email and other similar but it never works, it crashes or returns nul/undefined...
Any solution?
Hi Adriá,
Is your cloud code in your RegistrationRequest or RegistrationResponse?
If it's in registration request, your player won't have been created yet, so you won't be able to set data on it.
If it's in registration response, you'll need to pass the scriptData supplied to your RegistrationRequest on to your RegistrationResponse in order to use it. Like so:
RegistrationRequest:
Spark.setScriptData("email",Spark.getData().scriptData.email);
RegistrationResponse:
var email = Spark.getData().scriptData.email;
Try this out and let us know how you get on.
Regards,
Vinnie
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Adrià,
Have you been able to reproduce this inside the Test Harness? You can attach scriptData to your registrationRequest inside the Test Harness JSON builder.
After this, I would do a log on all the data coming in from the client to RegistrationRequest.
Spark.getLog().debug(JSON.stringify(Spark.getData()));
You can check this log in the script.log collection to see exactly what data came in. Of course, using the Test Harness you can also do this, with a trace of how your variables are changing over time.
Let me know if this helps you in diagnosing your bug further,
Pádraig
Adrià Martín
I added the scriptData in the test harness and made some test.
Using Spark.getLog().debug(JSON.stringfy(Spark.getData())); on the log i can see that the data from scriptData is not received... that's why the Spark.getData() in RegistrationResponse always return null or undefined.
Customer Support
Hi Adriá,
Is your cloud code in your RegistrationRequest or RegistrationResponse?
If it's in registration request, your player won't have been created yet, so you won't be able to set data on it.
If it's in registration response, you'll need to pass the scriptData supplied to your RegistrationRequest on to your RegistrationResponse in order to use it. Like so:
RegistrationRequest:
Spark.setScriptData("email",Spark.getData().scriptData.email);
RegistrationResponse:
var email = Spark.getData().scriptData.email;
Try this out and let us know how you get on.
Regards,
Vinnie
Adrià Martín
Thanks Vinnie, that was the solution. Adding the RegistrationRequest code was the solution.
-
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 2486 topics