Sign In Register

How can we help you today?

Start a new topic
Answered

Understanding System and Runtime collections

I have a game to which I am adding a back-end. That is, I now want players to be able to collect things, use consumables and register with social accounts. I am familiar with creating and working with Mongo collections but GS and how it works with Cloud Code is totally new to me.


I see that GS has 'System' collections in which you can store information against special system collections such as, Player. 

The docs say that these System collections are Read Only but I have been able to add properties to it through CC by following some of your tuts. 


I am not sure what you mean by the System collections being 'Read Only'.  

This question https://support.gamesparks.net/support/discussions/topics/1000069979

answers this by saying that one must use CC to Read the data and Write to it from other data in the Runtime collections. 


Am I correct in thinking that the 'Runtime' collections are the collections we create, which will hold and transfer data to the player collections when we use the set/getPrivate methods in CC instead of inserting and upserting directly like other mongo collections? Is this how I should be thinking about how the different collections interact? Can you please explain a bit more on this?


And lastly, do you have any best practices in regards to what things should NOT be stored in Player or any Best Practices in regards to constructing collections in the GS world?


Thank you


Best Answer

Hi Maria,


Baris is correct here, runtime collections are created by you and your players for storing game related data, system collections are handled by system operations. The privateData and scriptData mentioned are written to players using SparkPlayer in Cloud Code, If you look at SparkPlayer in our documentation you will see all the ways you can add data to a player in the player collection. For example if you wanted to credit the current players currency1 you would use "Spark.getPlayer().credit1(20);" in Cloud Code rather than doing a mongo query to find that field on a particular player and updating it with the desired amount. It's the same for the matchInstance collection, you can access matches using SparkMatch to add or remove players and get details on a particular match. For the challengeInstance collection you would use SparkChallenge. To get access a team in the team collection you would use SparkTeam. A ListTransactionsRequest will return the transaction details for the current player from the playerTransactionAudit collection. Hopefully that helps clear things up for you, if you have any further questions just let me know.


Thanks,

Liam


Yes, runtime collections are the ones we create. System collections are created and handled by the system. The only one you ever directly write to will probably be the player collection, which you do with the setPrivate and setScriptData functions. There is no other special interaction between them.


As for best practices, I think it's best to write small, frequently accessed data into the player collection (e.g. what level the player is at), and large data (e.g. the stars/completion time the player got from each level) into runtime collections. As far as I know, the player system collection is cached (though runtime collections are fast as well, and so this shouldn't make a noticeable difference for you). Of course, if you'll be doing NoSQL queries/aggregation, that should also inform how you structure your data.





Thanks for your input Baris! 

Answer

Hi Maria,


Baris is correct here, runtime collections are created by you and your players for storing game related data, system collections are handled by system operations. The privateData and scriptData mentioned are written to players using SparkPlayer in Cloud Code, If you look at SparkPlayer in our documentation you will see all the ways you can add data to a player in the player collection. For example if you wanted to credit the current players currency1 you would use "Spark.getPlayer().credit1(20);" in Cloud Code rather than doing a mongo query to find that field on a particular player and updating it with the desired amount. It's the same for the matchInstance collection, you can access matches using SparkMatch to add or remove players and get details on a particular match. For the challengeInstance collection you would use SparkChallenge. To get access a team in the team collection you would use SparkTeam. A ListTransactionsRequest will return the transaction details for the current player from the playerTransactionAudit collection. Hopefully that helps clear things up for you, if you have any further questions just let me know.


Thanks,

Liam

Oh Liam, this is very helpful! I am sure I will have more questions soon, but this has opened up my understanding of how to properly use GS.

Thank you very much

Login to post a comment