Sign In Register

How can we help you today?

Start a new topic
Answered

Spark.sendRequestAs not working

I'm trying to use Spark.sendRequestAs but my log isnt working. I have two scripts: ScriptA and ScritptB.

I also have two users. The first's id doesnt matter but the second does: 57b8a2279f0f9404a671f941


Now as the first undisclosed user, I run ScriptA which contains

 

Spark.getLog().debug("Script A has run");
Spark.sendRequestAs({"@class": ".LogEventRequest", "eventKey": "ScriptB"}, "57b8a2279f0f9404a671f941");

 Script B simply contains

 

Spark.getLog().debug("Script B has run");

 When I check my logs however, I only see "Script A has run"


I thought maybe "sendRequestAs" required parameters so I even tried Spark.sendRequestAs({"@class": ".LogEventRequest", "eventKey": "ScriptB", "SC": "1000"}, "57b8a2279f0f9404a671f941"); but alas, that doesnt work as well.


What am I doing wrong?


Best Answer

Hey Guys,


I think this may give you the desired results you are looking for


var request = new SparkRequests.LogEventRequest();

    request.eventKey = "ScriptB";

var response = request.ExecuteAs("57b8a2279f0f9404a671f941");


Using sendRequestAs won't execute any additional cloud code,


Hope this helps,

- Tony.



Hi,


For debugging purposes, try changing the request to "Spark.sendRequest" (aka sending as yourself). If this sends correctly, and logs, then I suspect your problem is with the id of the player being passed in as the second parameter of "sendRequestAs".


If nothing is happening, then it must be with how you are formulating your request json, even though your json looks to be correct.


-Pádraig

sendRequestAs doesnt work as well. The event I'm sending to doesnt take any parameters either so I'm not sure what's going wrong...

Sorry, I should have mentioned this earlier.


The standard Gamesparks events can be called using the Spark.sendRequest() method, however custom events like log-events cannot be called be called in this way.


An alternative is to wrap the functionality of the event inside of a Module, and have a function in the module take a playerId, essentially replicating exactly what you would be doing by calling an event.


Let me know if you need any more information,


-Pádraig


Oh man I am so confused.


The documentation for sendRequest has an example of

Spark.sendRequest({"@class": ".LogEventRequest", "eventKey": "SOT", "SC": "1000"});

 and sendRequestAs has an example of

Spark.sendRequestAs({"@class": ".LogEventRequest", "eventKey": "SOT", "SC": "1000"}, "1234567890");

I can't use custom events... so I tried doing both this in my test script

Spark.sendRequestAs(
                {
                    "@class": ".LogEventRequest", 
                    "eventKey": "MatchmakingRequest", 
                    "matchShortCode": "match", 
                    "skill": 0
                }, 
                    "57b8a2279f0f9404a671f941"
);

 and this

Spark.sendRequest(
                {
                    "@class": ".LogEventRequest", 
                    "eventKey": "MatchmakingRequest", 
                    "matchShortCode": "match", 
                    "skill": 0
                }
);

 with MatchmakingRequest having some custom code added like this

Spark.getLog().debug("MatchmakingRequest");

 Still not getting that second log. Does anyone have an example of sendRequestAs working or am I missing something here?

I guess it is simply forbidden to prevent infinite loops.


Jo

I imagine though it'd be treated like the scheduler then. If its forbidden it probably should not be in the documentation.

It's there for the standard Gamesparks requests.

If you want MatchmakingRequest, try this.

-----

var request = new SparkRequests.MatchmakingRequest();

request.matchShortCode = "CODE";

var response = request.SendAs(playerId);

-----


Answer

Hey Guys,


I think this may give you the desired results you are looking for


var request = new SparkRequests.LogEventRequest();

    request.eventKey = "ScriptB";

var response = request.ExecuteAs("57b8a2279f0f9404a671f941");


Using sendRequestAs won't execute any additional cloud code,


Hope this helps,

- Tony.


Hello, I don't know if this is a new bug, I followed the Hearthstone tutorial step by step until I reached the Matchmaking "MatchFoundMessage" editing. I tried everything but the CreateChallengeRequest won't run. I then tried to edit both the User and the Global MatchFoundMessage scripts, that's when the code worked, but it seemed to only execute the first line, and it did not even show the debug window as it does with other scripts. I'm guessing "Messages" can't be debugged, only requests can, I might be wrong. Please tell me why does the CreateChallengeRequest never work when sent from within cloud code.

that "first line was a ".setScriptData()" i used just to see if the script is working

the effects of the rest of the code were none existent, and even if they were, I had the wrong outcome and I didn't get the debug window when it ran

Can we get some clarification on the sendRequestAs functionality - I can't tell by the above responses from Customer Service if it is or is not working as designed.


I have 2 places where I am using Spark.sendRequestAs - and both appear to be working.  One calls a standard ChangeUserDetailsRequest and the other calls a custom event (which is just used to update a leaderboard - no code is executed).  


Am I to understand that if the request invoked by Spark.sendRequestAs actually has custom cloudcode associated with it, that this cloudcode will NOT execute?


Thanks in advance!!


Spark.sendRequest() and Spark.sendRequestAs() are the older way of invoking events via Cloud Code. The recommended approach is:


var request = new SparkRequests.ChangeUserDetailsRequest();

request.password = newPassword;

var response = request.Send() //or request.SendAs(playerId);


This won't execute any cloud code attached to the event. For this, you'd use Execute, e.g.


var request = new SparkRequests.LogEventRequest();

request.eventKey = myEventShortCode;

request.myAttribute = myValue;

var response = request.Execute //or request.ExecuteAs(playerId);


Hopefully this helps clear things up.


Regards,

Vinnie


1 person likes this

Thanks Vinnie!  - 

I would assume the docs need to be updated - https://docs.gamesparks.com/tutorials/cloud-code-and-the-test-harness/sending-requests-in-cloud-code.html

I couldn't find any API page on SparkRequests at all....

So does doing it this way (ExecuteAs) open up the same recursive/infinite loop problem that sendRequest/sendRequestAs were trying to avoid?


Login to post a comment