Sign In Register

How can we help you today?

Start a new topic
Answered

Change stored ScriptData in Cloud Code

 Is it possible to change only part of a ScriptData object through Cloud Code? What I want to do is to be able to have an event that I can call with only supplying some of the inputs it takes and then only change these values in the players ScriptData.


For instance, so far I've been doing something like this:

var player = Spark.getPlayer();
var value1 = Spark.getData().value1;
var value2 = Spark.getData().value2;

var gameInfo = {
    "value1" : value1,
    "value2" : value2
}

player.setScriptData("gameInfo ", gameInfo );

 This of course overwrites both values, so what I want to do is be able to leave out a parameter or maybe just pass '-1' or something and then keep whatever value is already stored for that parameter. I imagine something like this:

var player = Spark.getPlayer();
var scriptData= player.getScriptData("gameInfo");
var value1 = Spark.getData().value1;
if (value1 == -1)
    value1 = scriptData.<Some way of getting existing data>;
var value2 = Spark.getData().value2;
if (value2 == -1)
    value2 = scriptData.<Some way of getting existing data>;

var gameInfo = {
    "value1" : value1,
    "value2" : value2
}

player.setScriptData("gameInfo ", gameInfo );

 Is something like this possible? Other implementations are also welcome, I only put this code in here to give an example of what I want to achieve.


Kind regards,

Heino Jørgensen


Best Answer

Hello Heino Jørgensen,


You should be able to access your data like this:

var player = Spark.getPlayer();
var scriptData = player.getScriptData("gameInfo");

var value1 = scriptData["value1"];
var value2 = scriptData["value2"];

Is this what you're looking for?


Mantas


Answer

Hello Heino Jørgensen,


You should be able to access your data like this:

var player = Spark.getPlayer();
var scriptData = player.getScriptData("gameInfo");

var value1 = scriptData["value1"];
var value2 = scriptData["value2"];

Is this what you're looking for?


Mantas

Hi Heino,


I'm marking this topic as answered, if you have any further questions let us know.


Thanks,


Oisin

Sorry about the missing reply. Mantas solution worked just the way I needed, so the answer should indeed be marked as correct. Thanks.

 

Thanks Heino.

Oisin

Login to post a comment