Sign In Register

How can we help you today?

Start a new topic
Answered

Set ScriptData of the player account ?

Hi !


I am trying to set the script data that is retrieved when you do an AccountDetailsRequest.

However, the only way I can see so far is to create my own event and assign the player data from the cloud code. Is there any way to do that directly from the SDK (Unity) without creating an additional event ?


Best Answer

Hi Stephane,


You would have to set the scriptData somewhere first before it can be retrieved in the AccountDetailsRequest. If you're storing some basic stats that every player will have you can set these in the AuthenticationResponse/RegistrationResponse Cloud Code with something like the following.


 

//check if this is a new player
var newPlayer = Spark.getData().newPlayer
   
    //if its a new player
  if(Spark.getData().newPlayer === true){
       
      Spark.getPlayer().setScriptData("defaultValues", {
         "Lives": 0,
          "Health": 0,
          "Gold": 0,
          
        });
  }
       //if this is a returning player
       else
       {
       Spark.setScriptData("New Player ?", newPlayer);
     }

 

Doing this would make sure each new player would have these stats set to 0 by default when they sign up. Then you would need to have an event set up so your game could update these values from Unity when needed. If you have anymore questions just let me know.


Thanks,

Liam


Hi Stephane,


What data is it you are looking to set to scriptData when performing the AccountDetailsRequest ? If you can give me a bit more info on what you're looking to achieve here we can find a solution for you.


Thanks,

Liam

Hi Liam,


Well it was just storing some basic info about the player appearance and stats. I created an event and set up there the custom data to be retrieved by the AccountDetailsRequest. I guess I could also set it from the request itself by modifying the cloud code executed there, but I am fine with the event solution.

Answer

Hi Stephane,


You would have to set the scriptData somewhere first before it can be retrieved in the AccountDetailsRequest. If you're storing some basic stats that every player will have you can set these in the AuthenticationResponse/RegistrationResponse Cloud Code with something like the following.


 

//check if this is a new player
var newPlayer = Spark.getData().newPlayer
   
    //if its a new player
  if(Spark.getData().newPlayer === true){
       
      Spark.getPlayer().setScriptData("defaultValues", {
         "Lives": 0,
          "Health": 0,
          "Gold": 0,
          
        });
  }
       //if this is a returning player
       else
       {
       Spark.setScriptData("New Player ?", newPlayer);
     }

 

Doing this would make sure each new player would have these stats set to 0 by default when they sign up. Then you would need to have an event set up so your game could update these values from Unity when needed. If you have anymore questions just let me know.


Thanks,

Liam

Login to post a comment