Sign In Register

How can we help you today?

Start a new topic
Answered

Create custom objects...

Greetings,


I'm pretty new to Unity and game development. But found my way around quickly. Then I found about GameSparks, and thanks to it's amazing documentation I'm up and running in just a couple of days.


Well, sort of.


I am trying to make a football manager simulator game. So I want that when player registers, that his team is automatically created with 25 football players. Now, each of those 25 football players has his own stats (speed, agility, strength, shooting power, etc.).


I am trying to figure out the best way of doing this. I'm not asking that someone codes it for me, just want to be directed in the right track.


Cloud Code and creating custom JSON noSql tables? Or?


Thanks in advance for your time :)


Best Answer

Hi Marin,


You could do this in your AuthenticationResponse or RegistrationResponse with the following.


   

   //if its a new player (you wont need this check in the RegistrationResponse as it's always a new player)
  if(Spark.getData().newPlayer === true){
         
         //get the playerID  
        var playerID = Spark.getPlayer().getPlayerId();
        var players = {};
       
         //insert them into a unique document
         var success = Spark.runtimeCollection("players").insert({"_id":playerID,"players":players});
} 

   

You would just need to replace the blank "players" with your own default stats or whatever you require here. Using the playerId as the documents ID will make it easier for you to retrieve in Cloud Code.


Thanks,

Liam


Answer

Hi Marin,


You could do this in your AuthenticationResponse or RegistrationResponse with the following.


   

   //if its a new player (you wont need this check in the RegistrationResponse as it's always a new player)
  if(Spark.getData().newPlayer === true){
         
         //get the playerID  
        var playerID = Spark.getPlayer().getPlayerId();
        var players = {};
       
         //insert them into a unique document
         var success = Spark.runtimeCollection("players").insert({"_id":playerID,"players":players});
} 

   

You would just need to replace the blank "players" with your own default stats or whatever you require here. Using the playerId as the documents ID will make it easier for you to retrieve in Cloud Code.


Thanks,

Liam

@Customer Support

Liam


Thanks for the prompt reply. I see what you mean there, and it makes sense :)

If you could assist me in one more thing... I would like to register users via email, so they can retrieve their passwords, confirm account, etc.


I see a way of doing it manually, but why isn't email at least optional field by default in RegistrationRequest? Is there any other way expect my custom way? I mean a way that gamesparks has built in?

Hi Marin, 


This isn't default behavior so as to allow for freedom in the way you implement platform features. Instead we allow you to setScripData on Api Requests. In this way you can add the email as scriptData, then acquire it through cloud code to set it as script, or pirvateData on the Player in Cloud Code using our SparkPlayer class. 


Hope this answers your question.

Best Regards, Patrick. 

Login to post a comment