Sign In Register

How can we help you today?

Start a new topic
Answered

Querrying specific player data instead of everything?

I was reading the blog posts:
https://www.gamesparks.com/blog/writing-a-highly-scalable-server-authoritative-game-part-3/


It says you should gather only the data you need with specific querry instead of returning everything and filter out in the code. Makes lots of sense, of course, but I dunno how to do it.


How do I do that using unity sdk api AccountDetailsRequest(), for example, if I just want to get display name? 


If anyone can explainme or point to the documentation where this is explained, Id appreciate.


Best Answer

Hi Giuliano,


Yes, that's correct. You can think of Events that you create as custom calls into the GameSparks platform which runs the code you want (whatever you write in the Cloud Code for that event).

Returning data to the client is done as you suggested.


In reality, the "out of the box" API calls such as AccountDetailsRequest are pretty heavily optimised so you shouldn't be too afraid to call them even if it does return a little bit more data than you need.

You are right of course, you should still minimise these calls (e.g. maybe call it once every time the player logs on) and cache the results on the client. This reduces network load and makes your game more responsive for your players. In general, reducing the number and size of calls to the server is a good idea - every call takes some amount of time (even if it is very quick) so minimising this makes sense.


Kind regards,


Jonathan Hill.


Hi Guliano,


You can use the SparkPlayer calls in Cloud Code to access specific player details without having to do an AccountDetailsRequest.


//get the displayName
var displayName= Spark.getPlayer().getDisplayName();

  

Try that and let us know if you have any further questions.


Thanks,

Liam


1 person likes this

Hi Liam,


Im still not sure how I should get the display name from the client using unity sdk.
I just grasped a bit of Events and Cloud Code by following the tutorials.


So, to querry just for the display name, should I create an event (on the portal, say Get_DispName), and set it using:

  

Spark.setScriptData("disp name", Spark.getPlayer().getDisplayName());

  

  on the cloud code for the event, and then on the client use unity sdk LogEventRequest to get the data from the response ?
This is just for learning, in practice I think Id just use AccountDetailsRequest once and save everything for further use.


Answer

Hi Giuliano,


Yes, that's correct. You can think of Events that you create as custom calls into the GameSparks platform which runs the code you want (whatever you write in the Cloud Code for that event).

Returning data to the client is done as you suggested.


In reality, the "out of the box" API calls such as AccountDetailsRequest are pretty heavily optimised so you shouldn't be too afraid to call them even if it does return a little bit more data than you need.

You are right of course, you should still minimise these calls (e.g. maybe call it once every time the player logs on) and cache the results on the client. This reduces network load and makes your game more responsive for your players. In general, reducing the number and size of calls to the server is a good idea - every call takes some amount of time (even if it is very quick) so minimising this makes sense.


Kind regards,


Jonathan Hill.


1 person likes this
Login to post a comment