I know how i can get each value (rang, set, hp etc), except for _id.
What i am trying to do is to write a delete function of the object. But i need to get the object id first, to delete it.
List<GameSparks.Core.GSData> data = response.ScriptData.GetGSDataList("player_Data"); List<Runes> runeList = new List<Runes>();
for (int i = 0; i < data.Count; i++) {
//this is how i get each value int r = (int)data[i].GetInt("rang"); int h = (int)data[i].GetInt("hp"); int s = (int)data[i].GetInt("set");
//here is the error
int id = (int)data[i].GetGSData("_id").GetInt("$oid");
print("Get Id:" + id); }
How do i get id as an int?
Best Answer
C
Customer Support
said
over 5 years ago
Hi Kelvin,
The issue here seems to be due to a type mismatch. You're attempting to use 'GetInt' on the $oid field, but the value in this field is stored as a string. Could you try this with
string id = data[i].GetGSData("_id").GetString("$oid");
The issue here seems to be due to a type mismatch. You're attempting to use 'GetInt' on the $oid field, but the value in this field is stored as a string. Could you try this with
string id = data[i].GetGSData("_id").GetString("$oid");
Kelvin Petry
Hi,
i have my objects saved like this: https://puu.sh/tAW8H/2e4cff752a.png
I know how i can get each value (rang, set, hp etc), except for _id.
What i am trying to do is to write a delete function of the object. But i need to get the object id first, to delete it.
List<GameSparks.Core.GSData> data = response.ScriptData.GetGSDataList("player_Data");
List<Runes> runeList = new List<Runes>();
for (int i = 0; i < data.Count; i++) {
//this is how i get each value
int r = (int)data[i].GetInt("rang");
int h = (int)data[i].GetInt("hp");
int s = (int)data[i].GetInt("set");
//here is the error
int id = (int)data[i].GetGSData("_id").GetInt("$oid");
print("Get Id:" + id);
}
How do i get id as an int?
Hi Kelvin,
The issue here seems to be due to a type mismatch. You're attempting to use 'GetInt' on the $oid field, but the value in this field is stored as a string. Could you try this with
string id = data[i].GetGSData("_id").GetString("$oid");
Let us know if this works for you.
Regards,
Vinnie
- Oldest First
- Popular
- Newest First
Sorted by PopularKelvin Petry
Follow up question: How can i change an object with the same object id via cloudcode? I basicly just want to set "visible" on the object to false
var playerDataList = Spark.runtimeCollection("Runes");
playerDataList.update({
"$oid": Spark.getData().deleteID
},
{
"$set": {"visible": false}
},
false,
false
);
error is:
Customer Support
Assuming that 'deleteID' is a valid objectID, the query would be...
playerDataList.update({ "_id" : { "$oid": Spark.getData().deleteID }} );
Customer Support
Hi Kelvin,
The issue here seems to be due to a type mismatch. You're attempting to use 'GetInt' on the $oid field, but the value in this field is stored as a string. Could you try this with
string id = data[i].GetGSData("_id").GetString("$oid");
Let us know if this works for you.
Regards,
Vinnie
-
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