Sign In Register

How can we help you today?

Start a new topic
Answered

Can't get scriptData from registerRequest

In unity i call registerRequest: 

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

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


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

I added the scriptData in the test harness and made some test.

{
 "@class": ".RegistrationRequest",
 "displayName": "wefew",
 "password": "wefweewf",
 "segments": {},
 "userName": "hnhn",
 "scriptData" : {"email":"bla"}
}


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.


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:


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

Thanks Vinnie, that was the solution. Adding the RegistrationRequest code was the solution.

Login to post a comment