Sign In Register

How can we help you today?

Start a new topic
Answered

Custom Achievements through Cloud Code

 Hello,


I have an issue with the achievements. My goal is to give different ammount of currency to the players of a team, in a Leaderboard (LB). The ammount of currency needs to be calculated in cloud code by a formula (that takes into account the RANK of the player in the LB and his/her SCORE).
For that, I set up an Achievement (ACH) that is "empty" (it doesn't give any virtual good or currency, because we will do it through cloud code). ACH is linked to LB. Then, in AchievementEarnedMessage (CloudCode/UserMessages), I have implemented a method that calculates the currency with the formula, and gives the proper ammount of the currency to the player.
The problem comes when the code I wrote in AchievementEarnedMessage tries to access the RANK and the SCORE from the LB, the entries are not there yet, so the methods getRank() and getAttribute(SCORE) (from getEntriesFromPlayer) return an error saying that the entry is null ("Cannot call method \"getAttribute\" of null").

The curious thing is that the error only happens when the LB is set to "Calculate daily/weekly/monthly". I tried with the LB set up to Real-Time and it works (actually it works sometimes and sometimes not). The problem is that the LB must be set to Calculate, for game purposes.


I don't know what else to try, so if you could help me I would appreciate it very much.


Best Answer

Hi Javier,


You'll get null on the entries for a calculate leaderboard as although the scores are gathered when posted, the leaderboard itself is only created at calculation time so the entries will only be available then, so every day/week/month. If I'm understanding your requirements correctly what you could do here is create a realtime leaderboard that is partitioned by week feeding off a custom running total from the event on the calculated leaderboard. You could then use this leaderboard to get the data you require to calculate the currency reward all while leaving the calculate board to generate at the end of the day/week/month. Does that sound right to you ? 


Thanks,

Liam


Hi Liam
Thank you for the feedback. I tried what you said, I will see tomorrow the results.
I've observed that you posted a score (120) with a player named testUser01 on day 26. Throughout these days, four leaderboards have been created (27, 28, 29, 30), and testUser01 is in all of them, with the same score (120). If this set up were to work as I want, testUser01 would only appear in the 27 leaderboard (since he scored the day 26), but not in the rest of leaderboards (since it is suposed to start from 0 every day).
Are we missing here a filter similar to this: ${today:minusDays(1)} ,  in the leaderboard or the event or the running total?
Thank you!

 

Hi Liam,

Thank you for your reply. So, correct me if I'm wrong, your suggestion is:

- I let the "Calculate Daily" LB to be the one that triggers the ACH.
- In AchievementEarnedMessage I get the RANK and SCORE from the new LB (Real-Time, daily partitioned).

I think that could work. The only issue I see is that, since I have the scores set to SUM, I will need the new LB to, not only be partiitioned by day, but also take the scores posted only in the last day, starting from 0 every day. I have tried to do that following this:
https://docs.gamesparks.net/howtos/leaderboards-howtos/how-to-create-time-based-leaderboards

 
It doesn't seem to work for me. I have set a separate project called "Test Time LB" only for that purpose...you have full access to it if you want to check.


Thank you!
Javier

Answer

Hi Javier,


You'll get null on the entries for a calculate leaderboard as although the scores are gathered when posted, the leaderboard itself is only created at calculation time so the entries will only be available then, so every day/week/month. If I'm understanding your requirements correctly what you could do here is create a realtime leaderboard that is partitioned by week feeding off a custom running total from the event on the calculated leaderboard. You could then use this leaderboard to get the data you require to calculate the currency reward all while leaving the calculate board to generate at the end of the day/week/month. Does that sound right to you ? 


Thanks,

Liam

Hi Javier,


I've set up an event, leaderboard and running total in the test game for you, log in as a test user and post a score with the "scoreTest" event then go to the manage screen and check out the results, you'll see the score posted for todays partition but the calculate leaderboard will be blank until the scores are calculated tonight at midnight, a test achievement (which I created for you) should then be awarded to players in the top 3 places. The partitioned leaderboard will also start from 0 tomorrow in a fresh partition. Is that the functionality you were after ? The time used by the ${today} expression in the event will be for the stroke of midnight of the current day (all the scores posted after 00:00 of today). So todays partition would be the following "1464220800000". Try that configuration out and let me know if its giving you the results you need, then we'll look at the AchievementEarnedMessage.


Thanks,

Liam

Login to post a comment