Hi,
I am working on MMO game.I have to save multiple character and its info against single ID because in my game a player can save multiple heroes (can play from single one). I created an event, but when user told db to create character it simply update last information.
var CharacterDataList = Spark.runtimeCollection("CharacterData");
var playerID = Spark.getPlayer().getPlayerId();
var characterSelected = Spark.getData().CS;
var weaponLevel = Spark.getData().WL;
var cname = Spark.getData().NAME;
var wins = Spark.getData().WINS;
var loss = Spark.getData().LOSS;
var gold = Spark.getData().GOLD;
var currentCharacter = {
"playerID": playerID,
"characterSelected": characterSelected,
"weaponLevel": weaponLevel,
"name": cname,
"wins": wins,
"loss": loss,
"gold": gold
}; // we construct a new player from the data we are about to input into the player data
CharacterDataList.update({
"playerID": playerID
}, //Looks for a doc with the id of the current player
{
"$set": currentCharacter
}, // Uses the $set mongo modifier to set old player data to the current player data
true, // Create the document if it does not exist (upsert)
false // This query will only affect a single object (multi)
);
Above code will run on cloud. How can I save new character against this id. I found a command of Insert but I don’t know how to use it in my case to Add information. The Unity Code is below.
public void CreateCharacterData(){
new GameSparks.Api.Requests.LogEventRequest ()
.SetEventKey ("SAVE_CHARACTER_INFO")
.SetEventAttribute ("CS", "Humans")
.SetEventAttribute ("WL", 1)
.SetEventAttribute ("NAME", "ghfsdgfsj")
.SetEventAttribute ("WINS", 0)
.SetEventAttribute ("LOSS", 0)
.SetEventAttribute ("GOLD",100)
.Send((GameSparks.Api.Responses.LogEventResponse obj) => {
if(!obj.HasErrors){
print("Added Character");
}else{
print("Error");
}
});
}
I found a link but I am still confused 1.
Thanks in advance.
Regards.
Salam.