Sign In Register

How can we help you today?

Start a new topic
Answered

Setting ScriptData

Hi guys,


Been trying to find a way to add a custom field for each user, but i am having no luck at all.


I want every player to have a Rank field which increases or decreases depending on how many points they have etc. and so if someone gets a challenge they will know the Rank of their opponent. 


I have tried 

GSRequestData data = new GSRequestData().AddNumber("Rank",GameManager.Current.playerRank);
new ChangeUserDetailsRequest().SetScriptData(data).Send((response) =>{
if(response.HasErrors)
Debug.Log(response.Errors);
else
Debug.Log("ChangeUserDetailsRequest Success");
});


but when i then do 


new AccountDetailsRequest().Send((response) =>{
Debug.Log(response.JSON);
});


The scriptData is always null!


Kind Regards 

Abdullah


Best Answer

Hi Abdullah,


In Unity the SetScriptData function allows you to set the response ScriptData. So in this case I would recommend making a custom Cloud Code event to update the player's scriptData.


Make an event called "UpdateRank" with an attribute called "rank"


Then in Cloud Code -> Events -> UpdateRank and enter something along the lines of:


 

Spark.getPlayer().setScriptData("rank", Spark.getData().rank);

//Spark.getPlayer() loads the player

//Spark.getData() will grab any information in the response or request, in this case we want to get the "rank" attribute so we put it as Spark.getData().rank;

 


Then in Unity do a Log Event Request:


  

new LogEventRequest().SetEventKey("UpdateRank").SetEventAttribute("rank", GameManager.Current.playerRank).Send((response) =>
{
	if (response.HasErrors)
	{
		Debug.Log("Failed");
	}
	else
	{
		Debug.Log("Successful");
	}
});

 

You could also set it up to take JSON data if you like.


Shane


Answer

Hi Abdullah,


In Unity the SetScriptData function allows you to set the response ScriptData. So in this case I would recommend making a custom Cloud Code event to update the player's scriptData.


Make an event called "UpdateRank" with an attribute called "rank"


Then in Cloud Code -> Events -> UpdateRank and enter something along the lines of:


 

Spark.getPlayer().setScriptData("rank", Spark.getData().rank);

//Spark.getPlayer() loads the player

//Spark.getData() will grab any information in the response or request, in this case we want to get the "rank" attribute so we put it as Spark.getData().rank;

 


Then in Unity do a Log Event Request:


  

new LogEventRequest().SetEventKey("UpdateRank").SetEventAttribute("rank", GameManager.Current.playerRank).Send((response) =>
{
	if (response.HasErrors)
	{
		Debug.Log("Failed");
	}
	else
	{
		Debug.Log("Successful");
	}
});

 

You could also set it up to take JSON data if you like.


Shane

Thanks! Thats exactly what i needed for this! 

My follow up to this would be how would i setScriptData on a challenge? So if i wanted to send a score of 10 to another player?

I have got a system to get userIds from database so thats already good to go but now how do i create a challenge and send the score to that user for him to have his go.


I also posted this problem in a separate topic in more detail.


https://support.gamesparks.net/support/discussions/topics/1000050081

Login to post a comment