Sign In Register

How can we help you today?

Start a new topic
Answered

How to get player's language via cloud code?

Hi


I'm using ChangeUserDetailRequest to set player's language, but I cannot get it via could code API?

Please help.


Thanks

Jo


Best Answer

Hi Jo,


You could save the language to a players scriptData by setting the ChangeUserDetailsRequest Cloud Code to the following 


var lang = Spark.getData().language;

var setLanguage= Spark.getPlayer().setScriptData("language", lang);

Spark.setScriptData("language", lang)

 


You could then retrieve it with 

 

var language = Spark.getPlayer().getScriptData("language");

  

Let me know if this helps.


Thanks,

Liam



Hi Jo,


Can you clarify what steps you are trying and what is not working for you?

Thanks,


Oisin.

Hi Oisin:


in iOS client:

NSString *langID = [[NSLocale preferredLanguages] objectAtIndex:0];

GSChangeUserDetailsRequest* r = [[GSChangeUserDetailsRequest alloc] init];

[r setLanguage:langID];


In NoSql explorer, I saw that the language value is stored in player Object.

But in cloud code, how to get the language set by Client?

Thanks

Jo

Answer

Hi Jo,


You could save the language to a players scriptData by setting the ChangeUserDetailsRequest Cloud Code to the following 


var lang = Spark.getData().language;

var setLanguage= Spark.getPlayer().setScriptData("language", lang);

Spark.setScriptData("language", lang)

 


You could then retrieve it with 

 

var language = Spark.getPlayer().getScriptData("language");

  

Let me know if this helps.


Thanks,

Liam


Err...


    var language = Spark.getPlayer().getScriptData("language");

Hi Ryan,


Thanks for spotting that typo, have corrected it !


Liam

Login to post a comment