How to update a different player's score from an event in cloud code?
C
Curt Bererton
started a topic
over 6 years ago
Hello, I tried to find a similar topic on this, but was unable to get there from the docs. I believe I can load a different players' score, and submit a leaderboard request as follows:
var request = new SparkRequests.GetLeaderboardEntriesRequest();
However the default LeaderboardScore event submits a score for the authenticated player, not the target player. How can I submit a leaderboard score event for a player that is different from the one who is currently logged in? In this case if the attacking player loses, I want to get the defender a point on the leaderboard.
Any help would be appreciated!
Thanks.
Best Answer
C
Customer Support
said
over 6 years ago
Hi Curt,
You should use a SparkRequest for submitting the score as the other player also, you can read about how to configure a LogEventRequest through Cloud Code here. You can go through my example below to help you get started.
var request = new SparkRequests.LogEventRequest();
request.yourEventKey = ...; //the name of your event
request.yourEventAttribute = ...; //this will be your score attribute populated by your score var
var response = request.SendAs(playerID); //supply the ID of the player you wish to send the event as here
//A few notes on how you can send events with a SparkRequest.
var response = request.Send(); //Will send the event as the current player without executing the Cloud Code for the given event
var response = request.SendAs(playerID); //Will send the event for the supplied playerID without executing the Cloud Code for the given event
var response = request.Execute(); //Will send the event as the current player and Execute the Cloud Code for that event
var response = request.ExecuteAS(playerID); //Will send the event for the supplied playerID and Execute the Cloud Code for the given event
Try that and let me know if you have any further questions.
You should use a SparkRequest for submitting the score as the other player also, you can read about how to configure a LogEventRequest through Cloud Code here. You can go through my example below to help you get started.
var request = new SparkRequests.LogEventRequest();
request.yourEventKey = ...; //the name of your event
request.yourEventAttribute = ...; //this will be your score attribute populated by your score var
var response = request.SendAs(playerID); //supply the ID of the player you wish to send the event as here
//A few notes on how you can send events with a SparkRequest.
var response = request.Send(); //Will send the event as the current player without executing the Cloud Code for the given event
var response = request.SendAs(playerID); //Will send the event for the supplied playerID without executing the Cloud Code for the given event
var response = request.Execute(); //Will send the event as the current player and Execute the Cloud Code for that event
var response = request.ExecuteAS(playerID); //Will send the event for the supplied playerID and Execute the Cloud Code for the given event
Try that and let me know if you have any further questions.
Thanks,
Liam
1 person likes this
C
Curt Bererton
said
over 6 years ago
Ah, perfect. I missed the SendAs and ExecuteAs functionality in the docs. I'll give that a go. Thank you!
Customer Support
said
over 6 years ago
Hi Curt,
No problem, if you have any further questions just let me know.
Curt Bererton
Hello, I tried to find a similar topic on this, but was unable to get there from the docs. I believe I can load a different players' score, and submit a leaderboard request as follows:
var request = new SparkRequests.GetLeaderboardEntriesRequest();
request.leaderboards = ["MatchScoreLeaderboard"];
request.player = targetID;
var response = request.Send();
if( !response.error) {
if(response.MatchScoreLeaderboard != undefined){
//Spark.getLog().debug(response.MatchScoreLeaderboard);
var score = response.MatchScoreLeaderboard.score;
score = score +1;
// now submit the new leaderboard score
var response2 = Spark.sendRequest({
"@class": ".LogEventRequest",
"eventKey": "LeaderboardScore",
"score": score
});
//Spark.getLog().debug(response2);
}
}
However the default LeaderboardScore event submits a score for the authenticated player, not the target player. How can I submit a leaderboard score event for a player that is different from the one who is currently logged in? In this case if the attacking player loses, I want to get the defender a point on the leaderboard.
Any help would be appreciated!
Thanks.
Hi Curt,
You should use a SparkRequest for submitting the score as the other player also, you can read about how to configure a LogEventRequest through Cloud Code here. You can go through my example below to help you get started.
Try that and let me know if you have any further questions.
Thanks,
Liam
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Curt,
You should use a SparkRequest for submitting the score as the other player also, you can read about how to configure a LogEventRequest through Cloud Code here. You can go through my example below to help you get started.
Try that and let me know if you have any further questions.
Thanks,
Liam
1 person likes this
Curt Bererton
Ah, perfect. I missed the SendAs and ExecuteAs functionality in the docs. I'll give that a go. Thank you!
Customer Support
Hi Curt,
No problem, if you have any further questions just let me know.
Thanks,
Liam
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2487 topics