Sign In Register

How can we help you today?

Start a new topic
Answered

Leaderboard and cloud code

Hi


I would like to update leaderboards when game ended from Cloud code, and the leaderboard is updated by LogEventRequest.

But LogEventRequest cannot be issue in Cloud code by sendRequest or sendRequestAs.

So how to achieve this?


Thanks a lot

Jo


Best Answer
Hey Jo,

 

You can call a LogEventRequest from cloud-code, you just want to be careful you don't end up calling recursive loops though.
You can call your LogEventRequest using the following code...

 

var response  = Spark.sendRequest({
 "@class": ".LogEventRequest",
 "eventKey": "sendLogEvent"
});

Theres a very handy API for cloud-code requests here.

But, i think your problem doesn't need to insert a leaderboard entry through cloud-code.
The way the leaderboards get their entries is by sending a LogEventRequest with the attribute you want to insert for the player, like the score.
So, this event is sent from the client at the end of the game with the player score and you dont need any cloud-code.

There's a tutorial here on how to set those events up.

Let me know if that helps, or if ive misunderstood something.

Sean



2 people have this question

Answer
Hey Jo,

 

You can call a LogEventRequest from cloud-code, you just want to be careful you don't end up calling recursive loops though.
You can call your LogEventRequest using the following code...

 

var response  = Spark.sendRequest({
 "@class": ".LogEventRequest",
 "eventKey": "sendLogEvent"
});

Theres a very handy API for cloud-code requests here.

But, i think your problem doesn't need to insert a leaderboard entry through cloud-code.
The way the leaderboards get their entries is by sending a LogEventRequest with the attribute you want to insert for the player, like the score.
So, this event is sent from the client at the end of the game with the player score and you dont need any cloud-code.

There's a tutorial here on how to set those events up.

Let me know if that helps, or if ive misunderstood something.

Sean


But it makes sense to update the leaderboard through cloud code, doesn't it, to prevent cheating? Especially when you're using the JavaScript SDK, one could easily send a LogEventRequest with a very high score and end up as number 1 on the leaderboard.


2 people like this
Login to post a comment