Sign In Register

How can we help you today?

Start a new topic
Answered

What is the difference between scriptData and eventAttributes?

 Hi Guys,


I've been following get started tutorials and I have a slight misunderstanding of concepts scriptData and eventAttribute.


In the introduction of tutorial #3 Using Cloud Code this is used to save data:

var POSV = Spark.getData().POS;
 
Spark.getPlayer().setScriptData("POSV", POSV);

and retrieval:

var POSV = Spark.getPlayer().getScriptData("POSV");
 
Spark.setScriptData("POS", POSV);

 

However if I read further in the documentation for Unity, this code is used:

 

new GameSparks.Api.Requests.LogEventRequest().SetEventKey("SAVE_PLAYER").SetEventAttribute("XP", 123456).SetEventAttribute("POS", playerPosition.ToString()).SetEventAttribute("GOLD", 100).Send((response) => {
	if (!response.HasErrors) {
		Debug.Log("Player Saved To GameSparks...");
	} else {
		Debug.Log("Error Saving Player Data...");
	}
});

 

and some of the retrieval:


var playerExperiance = Spark.getData().XP; // we get the xp input from Unity
var playerGold = Spark.getData().GOLD; // Get the gold input from Unity
var playerPos = Spark.getData().POS; // and the position input from Unity

 

Why in first example scriptData is used while in the second one is used setEventAttribute and getData?


Best Answer
Hi Ondrej,

scriptData is used to add extra information to existing collections, requests, responses etc. In the first example above, a scriptData field called "POSV" is being added to the player collection to keep track of the players position.

Attributes, on the other hand, are added to events you create to define what information needs to be sent when logging said event. In the second example, a custom event called "SAVE_PLAYER" is being logged and its attributes are being set, then these same attributes are being retrieved in the event's cloud code.

Any information your custom event needs can be defined as an attribute; as a result, scriptData is unavailable for custom events.

Hope this clears things up for you.

Regards,
Vinnie




1 Comment

Answer
Hi Ondrej,

scriptData is used to add extra information to existing collections, requests, responses etc. In the first example above, a scriptData field called "POSV" is being added to the player collection to keep track of the players position.

Attributes, on the other hand, are added to events you create to define what information needs to be sent when logging said event. In the second example, a custom event called "SAVE_PLAYER" is being logged and its attributes are being set, then these same attributes are being retrieved in the event's cloud code.

Any information your custom event needs can be defined as an attribute; as a result, scriptData is unavailable for custom events.

Hope this clears things up for you.

Regards,
Vinnie





1 person likes this
Login to post a comment