Sign In Register

How can we help you today?

Start a new topic
Answered

General Guidance/Information

Hello fellow developers,


I have recently switched from another BaaS to Gamesparks, and I would like some general guidance about how to correctly operate with GameSparks. I have gone through the ¨Get started¨ documentation and I have a general idea, but still flooded with doubts.


Data (collections?)


I have data that is related with the game (GameData) and won't change often, and data related to players that will change/update often (PlayerData).


An example of  GameData would be the cost uf upgrading my units: 


 

{
  "UpgradeGoldCost": [
    {
      "Rarity": "COMMON",
      "Values": [
        5,
        20,
        50,
        150,
        400,
        1000,
        2000,
        4000,
        8000,
        20000,
        50000,
        100000
      ]
    },
    {
      "Rarity": "RARE",
      "Values": [
        50,
        150,
        400,
        1000,
        2000,
        4000,
        8000,
        20000,
        50000,
        100000
      ]
    },
    {
      "Rarity": "EPIC",
      "Values": [
        400,
        2000,
        4000,
        8000,
        20000,
        50000,
        100000
      ]
    },
    {
      "Rarity": "LEGENDARY",
      "Values": [
        5000,
        20000,
        50000,
        100000
      ]
    }
  ]
}

 

That data could be stored client-side but I prefer it to be dynamic and be able to change it without uploading a new binary to the stores.


Afaik in GameSparks everything related with storing data goes inside Collections. Should this go as RunTime or MetaData collection?


The same questions goes for PlayerData, which contains what Units have they unlocked, what lvl are those units, how many repeated units, initial Rankin/ELO and more. PlayerData unlike GameData will change often.


Also, every time I add a collection, it auto generates a field _id like {"_id":{"$oid":"5a2ead9946e0fb0001a82aa8"},"UpgradeGoldCost":. Is there any way I can specify that ID manually? I'd like the ID to be UpgradeGoldCost and not 5a2ead9946e0fb0001a82aa8


I guess I can access that data from my client (Unity3D in my case) with something like (pseudo code) GameSparks.API.Collections.GetCollection("UpgradeGoldCost") and that will return a Json, am I right?


Events and CloudScript


Everytime a new player is registered, I want to give him a default PlayerData, which means, all players start with the same units at the same level, same ranking and a predefined BattleSquad (a set of units you bring to the battlefield). You can modify your BattleSquad later on but you are given a default one.


I should start by creating a Collectrion (again not sure if metadata or runtime) called for example DefaultPlayerData containing all the initial data I want to give to new players.


Then ,if I'm not wrong, I need to create and Event and a custom CloudScript. First I need to create the Event NewPlayerRegistered, but I don't know how to link that event with the actual event of a new player registering so it triggers my CloudScript.


And once I have that event to trigger with new registers, I should create a CloudScript Similar to (pseudocode) Spark.GetPlayer().SetDataCollection("DefaultPlayerData") and link that CloudScript to that Event. Again, am I going in the correct direction? 


Any hint, correction or advice will be extremely helpful. I'm still trying to get the basics and understand how Collections, Events and CloudScripts are linked between them, because seems to me those three elements are the core of GameSparks.


Best Answer

Hi Ivan,


Just a quick note on Runtime Vs Meta-collections. 

Meta-collections don’t get reset when you publish your game. Runtime-collections are only specific to the game.  

The difference is that meta-collections can be moved from preview to live without being reset. This makes them very useful for persistent data like items(or in your case upgradeCost). It is also important to note that meta-collections are not editable while the game is live, so they are much safer to use for game-configuration information.


Runtime-Collections by contrast, can be altered at Runtime, and should be used for storing data generated at Runtime and not static configuration data. Note that they will not carry over to live from review and will be reset once the game is published to live. Here's a quick link to managing data persistence in Gamesparks.


For your use case I would go with GameData in a meta collection as it seems to be changed infrequently and a Runtime-collection for Player-Data as it will update constantly.


The _id is generated for each document in a collection as it reference inside the collection. You could add JSON to the Document with "ID" : "UpgradeGoldCost" which will allow you to find a document with the "ID" : "UpgradeGoldCost" in your GameData Meta Collection with something like: 

 

var Cost = Spark.metaCollection('GameData').find({ "ID" : "UpgradeGoldCost" }, { "_id" : 0 });


Accessing collections and Data in Unity

https://docs.gamesparks.com/getting-started/using-cloud-code/unity-cloud-code.html#loading-data


To add JSON on behalf of a player to a collection upon registration you could make use of the Registration Response, here is some sample code which adds a user details to a Runtime-Collection upon registration

if(Spark.getData().error === undefined)

{

    Spark.runtimeCollection("playerList").insert(

        {

            "playerId" : Spark.getPlayer().getPlayerId(),

            "displayName" : Spark.getPlayer().getDisplayName(),

            "userName" : Spark.getPlayer().getUserName(),

        });

}


Do you think these solutions will fit for your use case?


Kind Regards

Ronan



Answer

Hi Ivan,


Just a quick note on Runtime Vs Meta-collections. 

Meta-collections don’t get reset when you publish your game. Runtime-collections are only specific to the game.  

The difference is that meta-collections can be moved from preview to live without being reset. This makes them very useful for persistent data like items(or in your case upgradeCost). It is also important to note that meta-collections are not editable while the game is live, so they are much safer to use for game-configuration information.


Runtime-Collections by contrast, can be altered at Runtime, and should be used for storing data generated at Runtime and not static configuration data. Note that they will not carry over to live from review and will be reset once the game is published to live. Here's a quick link to managing data persistence in Gamesparks.


For your use case I would go with GameData in a meta collection as it seems to be changed infrequently and a Runtime-collection for Player-Data as it will update constantly.


The _id is generated for each document in a collection as it reference inside the collection. You could add JSON to the Document with "ID" : "UpgradeGoldCost" which will allow you to find a document with the "ID" : "UpgradeGoldCost" in your GameData Meta Collection with something like: 

 

var Cost = Spark.metaCollection('GameData').find({ "ID" : "UpgradeGoldCost" }, { "_id" : 0 });


Accessing collections and Data in Unity

https://docs.gamesparks.com/getting-started/using-cloud-code/unity-cloud-code.html#loading-data


To add JSON on behalf of a player to a collection upon registration you could make use of the Registration Response, here is some sample code which adds a user details to a Runtime-Collection upon registration

if(Spark.getData().error === undefined)

{

    Spark.runtimeCollection("playerList").insert(

        {

            "playerId" : Spark.getPlayer().getPlayerId(),

            "displayName" : Spark.getPlayer().getDisplayName(),

            "userName" : Spark.getPlayer().getUserName(),

        });

}


Do you think these solutions will fit for your use case?


Kind Regards

Ronan


Great information Ronan. Thanks a lot for your time.


It now makes sense to me the Runtime vs Meta collections, and it perfectly fits for my needs.


One thing I was afraid of was to modify the stats of a Unit in my game when the game was Live. Two players could have the same unit but with different stats during a match, creating inconsistencies. Meta collections prevent that.


Thanks a lot for the info about Events, I missunderstood them at first.


Also sorry for the delay, I'm taking some days off for christmas! If I get stuck I'll be sure to ask for help here again :)

Login to post a comment