I have the following code I use to get the values out of some scriptData...
var list = new GSData(r.ScriptData).GetObjectList("playerCustomData").ToArray();
foreach (var l in list)
{
var dic = (Dictionary<string, object>)l;
var name = dic["name"].ToString();
}
This works fine, but what I am trying to do now is get the actual object ID stored in the $oid field in the collection, but I'm not sure how to do this.
Greg Quinn
I have the following code I use to get the values out of some scriptData...
This works fine, but what I am trying to do now is get the actual object ID stored in the $oid field in the collection, but I'm not sure how to do this.
Hi Greg,
You can set your own id using:
Spark.runtimeCollection("playerLives").insert({"_id" : "yourCustomId", "playerId":Spark.getPlayer().getPlayerId()});
Alternatively, to make the it more readable for Unity:
//find a document
activeDocument = activeCollection.findOne({"_id" : {"$oid" : idToFind}});
//Clean up the id so it's easier to read
activeDocument.Id = activeDocument._id.$oid;
delete activeDocument._id;
instead of
{
"@class": ".LogEventResponse",
"scriptData": {
"object": {
"_id": { $oid : "55cc930de4b0098175ad8388" }
}
}
}
To generate a GUID you would use something like this,
var myGuid = guid();
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4();
}
Thanks,
Liam
1 person has this question
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstIrakli Geleishvili
You can create an event and pass back to your application any data using Spark.setScriptError( "report", {key:"someString"} );
From your app you can request event by logEventRequest.
Script Error looks like thing to avoid, but it's good to use for returning some data to app after requests.
Use this reference for info about cloud code usage:
https://docs.gamesparks.net/documentation/gamesparks-service-cloud-code-api
Greg Quinn
Also how do I generate a GUID in cloud code?
Customer Support
Hi Greg,
You can set your own id using:
Spark.runtimeCollection("playerLives").insert({"_id" : "yourCustomId", "playerId":Spark.getPlayer().getPlayerId()});
Alternatively, to make the it more readable for Unity:
//find a document
activeDocument = activeCollection.findOne({"_id" : {"$oid" : idToFind}});
//Clean up the id so it's easier to read
activeDocument.Id = activeDocument._id.$oid;
delete activeDocument._id;
instead of
{
"@class": ".LogEventResponse",
"scriptData": {
"object": {
"_id": { $oid : "55cc930de4b0098175ad8388" }
}
}
}
To generate a GUID you would use something like this,
var myGuid = guid();
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return s4() + s4() + s4() + s4() + s4() + s4() + s4() + s4();
}
Thanks,
Liam
1 person likes this
-
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 2487 topics