Sign In Register

How can we help you today?

Start a new topic
Answered

Access request script data in the response handler

I want to access the scriptdata I set in the request in the response handler.

Is it possible ? Is there a safe workaround ?


Best Answer

Thank you very much for your reply. Your suggestion helped . I implemented 

    

function setRequestData(){

    var data = Spark.getData()["requestData"];
     Spark.setScriptData("scriptData",data);
}

function getRequestData(){
  var data =Spark.getData()["scriptData"]["requestData"];
   return  data;
}

 

I have some minor annoyances with it. now  that data is also persisted down to the client  and I have to manually remove the "requestData" before cloud code exits ..

Do you have any idea ? 


Answer

Thank you very much for your reply. Your suggestion helped . I implemented 

    

function setRequestData(){

    var data = Spark.getData()["requestData"];
     Spark.setScriptData("scriptData",data);
}

function getRequestData(){
  var data =Spark.getData()["scriptData"]["requestData"];
   return  data;
}

 

I have some minor annoyances with it. now  that data is also persisted down to the client  and I have to manually remove the "requestData" before cloud code exits ..

Do you have any idea ? 

Glad it helped.  I didn't find any other option other than clearing it in response code handler if you don't want it to reach client . 

May be Sparks team can give more info on this.

Sorry for asking you this but .. if you have some knowledge about facebook login  , could you look at my facebook login question ? 


https://support.gamesparks.net/support/discussions/topics/1000055064

You can use Spark.SetScriptData to do that.

Once u set data in Request cloud code with above method, the data will be passed to Response cloud code and inturn to the client.


here is an example - 

 

Request cloud code
      Spark.SetScriptData("state","RUNNING");


Response Cloud code:
var state = Spark.getData().scriptData["state"];

 This as per documentation of Spark class.

When scriptData is set to a request, it gets set against the response that will be returned to the player. This allows basic communication between request and response scripts.

 

Let me know if you have any trouble in using this.