Created
June 30, 2017 02:11
-
-
Save agramonte/3c01f7d74cc38870c89269ee0bd15280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//URL | |
/* | |
https://preview.gamesparks.net/callback/<gameAPIKey>/postScore/<credentialSecret>? | |
score=<playerScore> -- Needs to always be called score but it could represent anything. Whatever is being counted by the event. | |
&password=<playerPassword> | |
&username=<playerUsername> | |
&eventname=<leaderboardEventName> -- The name of the event that is attached to the leaderboard. | |
*/ | |
var score = Spark.getData().score; | |
var uPwd = Spark.getData().password; | |
var uName = Spark.getData().username; | |
var eventname = Spark.getData().eventname; | |
var authenticationResponse = Spark.sendRequest( | |
{ | |
"@class": ".AuthenticationRequest", | |
"password": uPwd, | |
"userName": uName | |
} | |
); | |
if (authenticationResponse.error == null) { | |
var logEventRequest = new SparkRequests.LogEventRequest(); | |
logEventRequest.eventKey = eventname; | |
logEventRequest.score = score; | |
var logEventResponse = logEventRequest.ExecuteAs(authenticationResponse.userId); | |
if (logEventResponse.error == null) { | |
Spark.setScriptData("RESPONSE_RAW", '{"Status":"Success"}'); | |
} else { | |
Spark.getLog().error(logEventResponse) | |
Spark.setScriptData("RESPONSE_RAW", '{"Status": ""}'); | |
} | |
} else { | |
Spark.getLog().error(authenticationResponse) | |
Spark.setScriptData("RESPONSE_RAW", '{"Status": ""}'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment