Sign In Register

How can we help you today?

Start a new topic
Answered

Best method to store Static data

Hello what is the best method to manage static game data, which do not belong to a player but for example enemy stats, enemy loot tables, quests. i tried to use "properties" but i found not handy to set complex special data like list of classes


where would you add this ?


got an other question, is it not good for performance to have a lot of field likes 200 + in player script data?

any way to optimize?


Best Answer

Hi Damien,


The best place to store the static game data such as enemy stats, enemy loot tables, quests, game config etc. would be in a meta collection, reason being that you can include meta collections when you publish a snapshot to live, so you can tweak your settings in preview and when happy with them, push them to live without any downtime.


A document size has a limit of 16mb so you could in theory put the data in the player document although personally I'd recommend putting this data into a collection. Have you any examples of the data which you would like to store in scriptData ?

 

If you were to use a collection to store the data you could do something like the following. In the AuthenticationResponse have this

  

//load the collection
var PlayerStorage = Spark.runtimeCollection("PlayerStorage");

//check if this is a new player
var newPlayer = Spark.getData().newPlayer
   
    //if its a new player
  if(Spark.getData().newPlayer === true){
         
         //get the playerID  
         var playerID = Spark.getPlayer().getPlayerId()
       

         //insert them into a unique document
         var success = Spark.runtimeCollection("PlayerStorage").insert({"_id":playerID,"displayName":userName})

else
{
//do something else
}

//Then whenever you needed to access a document for a particular player in Cloud Code you could find it with 

var getPlayer = PlayerStorage.findOne({"_id" : Spark.getPlayer().getPlayerId()});

  

If you have any ore questions just let me know.


Thanks,

Liam



Answer

Hi Damien,


The best place to store the static game data such as enemy stats, enemy loot tables, quests, game config etc. would be in a meta collection, reason being that you can include meta collections when you publish a snapshot to live, so you can tweak your settings in preview and when happy with them, push them to live without any downtime.


A document size has a limit of 16mb so you could in theory put the data in the player document although personally I'd recommend putting this data into a collection. Have you any examples of the data which you would like to store in scriptData ?

 

If you were to use a collection to store the data you could do something like the following. In the AuthenticationResponse have this

  

//load the collection
var PlayerStorage = Spark.runtimeCollection("PlayerStorage");

//check if this is a new player
var newPlayer = Spark.getData().newPlayer
   
    //if its a new player
  if(Spark.getData().newPlayer === true){
         
         //get the playerID  
         var playerID = Spark.getPlayer().getPlayerId()
       

         //insert them into a unique document
         var success = Spark.runtimeCollection("PlayerStorage").insert({"_id":playerID,"displayName":userName})

else
{
//do something else
}

//Then whenever you needed to access a document for a particular player in Cloud Code you could find it with 

var getPlayer = PlayerStorage.findOne({"_id" : Spark.getPlayer().getPlayerId()});

  

If you have any ore questions just let me know.


Thanks,

Liam


im trying to understand the runtime collection need to be created before ?


in your example we do: 

//load the collection

var PlayerStorage = Spark.runtimeCollection("PlayerStorage");


but how do you create it first ?



for example i have this:


 //stats

    Spark.getPlayer().setScriptData("stat_points_left", 0);

    Spark.getPlayer().setScriptData("stat_added_strength", 0);

    Spark.getPlayer().setScriptData("stat_added_stamina", 0);

    Spark.getPlayer().setScriptData("stat_added_dexterity", 0);

    Spark.getPlayer().setScriptData("stat_added_quickness", 0);

    Spark.getPlayer().setScriptData("stat_added_empathy", 0);

    //skills rank

    Spark.getPlayer().setScriptData("skill_attack", 0);

    Spark.getPlayer().setScriptData("skill_critical_power", 0);

    Spark.getPlayer().setScriptData("skill_health", 0);

    Spark.getPlayer().setScriptData("skill_health_regen", 0);

    Spark.getPlayer().setScriptData("skill_energy", 0);

    Spark.getPlayer().setScriptData("skill_energy_regen", 0);

    Spark.getPlayer().setScriptData("skill_sneaking", 0);

    Spark.getPlayer().setScriptData("skill_hit_chance", 0);


how can i add this to the player default collection ?

then how can i update a value like "skill_energy"?

Hey Damien,

The runtime-Collection is created automatically as soon as you call Spark.runtimeCollection("PlayerStorage");

 

Hey Damien,

You should set that script data alltogether in one form.
For example...


 

var form = {
	"skill_attack" : 0,
	"skill_critical_power" : 0,
	"skill_health" : 0,
	"skill_health_regen" : 0,
	"skill_energy" : 0,
	"skill_energy_regen" : 0,
	"skill_sneaking" : 0,
	"skill_hit_chance" : 0

}

Spark.getPlayer().setScriptData("extraStuff", form);


Then to get a value you can use the following....

 

Spark.getPlayer.getSciptData("extraStuff").skill_attack

 

 

And updating a value, you edit the form, and set it again....


 

var form = Spark.getPlayer.getSciptData("extraStuff");

form.skill_attack = 10;

Spark.getPlayer.setSctipData("extraStuff", form);

 

And thats it.
Hope that helps.

Sean

 

Login to post a comment