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
T
Tech Support
said
over 5 years ago
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"];
I'm marking this topic as answered, if you have any further questions let us know.
Thanks,
Oisin
H
Heino Jørgensen
said
over 5 years ago
Sorry about the missing reply. Mantas solution worked just the way I needed, so the answer should indeed be marked as correct. Thanks.
Customer Support
said
over 5 years ago
Thanks Heino.
Oisin
Tech Support
said
over 5 years ago
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"];
Heino Jørgensen
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:
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:
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
Hello Heino Jørgensen,
You should be able to access your data like this:
Is this what you're looking for?
Mantas
- Oldest First
- Popular
- Newest First
Sorted by PopularCustomer Support
Hi Heino,
I'm marking this topic as answered, if you have any further questions let us know.
Thanks,
Oisin
Heino Jørgensen
Customer Support
Thanks Heino.
Oisin
Tech Support
Hello Heino Jørgensen,
You should be able to access your data like this:
Is this what you're looking for?
Mantas
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2486 topics