Sign In Register

How can we help you today?

Start a new topic
Answered

Create a leaderboard with percentage of games won

I want to create a game for the percentage of games won by the player. I have two events (one for the number of games played and another of the games the player has won). Want I don't understand is how to create the leaderboard with this two values to get the value that I want. Is this even possible?


Best Answer
Hey Ines,

This is very simple for the information you have.
You just need a log-event for when the player wins a new game, and another which will submit the percentage to your leaderboard.

When a game is won, you call the 'calculatePercentage' event from the client, which will add one to the number of games won and the number of games played
You need to then get the number of total games participate in.

The calculation is ...

var percent = (games won / total games played) * 100

Then send this score to your leaderboard log-event. You can use MAX or LAST for the running total.

var req = new SparkRequests.LogEventRequest();
    req.eventKey = "submitPercent";
    req.percent = percent
    var resp = req.Execute();

Of course, then a game is played and the game is not won, you need a logevent to update the number of games played too.

 Hope that helps,

Sean


Sorry... I want to create a LEADERBOARD for the percentage of games won.

Answer
Hey Ines,

This is very simple for the information you have.
You just need a log-event for when the player wins a new game, and another which will submit the percentage to your leaderboard.

When a game is won, you call the 'calculatePercentage' event from the client, which will add one to the number of games won and the number of games played
You need to then get the number of total games participate in.

The calculation is ...

var percent = (games won / total games played) * 100

Then send this score to your leaderboard log-event. You can use MAX or LAST for the running total.

var req = new SparkRequests.LogEventRequest();
    req.eventKey = "submitPercent";
    req.percent = percent
    var resp = req.Execute();

Of course, then a game is played and the game is not won, you need a logevent to update the number of games played too.

 Hope that helps,

Sean