Award Achievement Issue
-
Hi there,
I am attempting to award some achievements via cloud code, and am running into an error that I can't seem to rectify with the existing documentation. I'm getting the error:
"Script Error (Line 79, Column 0): Can't find method com.braincloud.core.service.scripting.proxy.GamificationServiceProxy.awardAchievements(object)."
And code causing the error:
// process achievements, put them both here so we only access proxy if we need it (for minimal api count) if( statTotalMeters+meters >= PERSISTANCE_TRAVEL_THRESHOLD || statLandings+padsLanded >= SANCT_THRESHOLD) { var gamificationService = bridge.getGamificationServiceProxy(); var achievementIds = []; if(statTotalMeters+meters >= PERSISTANCE_TRAVEL_THRESHOLD) { achievementIds.push(PERSISTANCE_ID); } if(statLandings+padsLanded >= SANCT_THRESHOLD) { achievementIds.push(SANCT_ID); } var achievementRes = gamificationService.awardAchievements(achievementIds) }
Everything "feels" right but it's likely something silly I'm doing wrong?
Thanks,
Davis -
Your code looks good, but awardAchievements takes an extra boolean parameter in cloud code, includeMetaData, which controls if the extra achievement metadata is returned in the json response.
var includeMetaData = false; var achievementRes = gamificationService.awardAchievements(achievementIds, includeMetaData);
The documentation will be updated to show the missing value.
Thanks for reporting the issue.
-
Hi David,
Thanks for reporting this - it looks like the signature of that method changed over time, but we didn't update the cloud-code version of the call.
The cloud-code version of that call requires an additional boolean parameter - "includeMetadata" - which determines how much data is returned in the result.
If true, the result of awarding an achievement looks like this (we've since determined the client has likely retrieved/cached that extra data anyway, so there isn't normally a need to return it):
{ "data": { "achievements": [ { "extraData": null, "googleAchievementId": null, "achievementId": "EGG_ACH02", "description": "You saved 10,000 Animals!", "title": "Saviour", "appleAchievementId": "", "steamEnabled": false, "fbGamePoints": 10, "imageUrl": "https://internal.braincloudservers.com/files/portal/g/11281/metadata/achievements/EGG_ACH02.png", "steamAchievementId": "", "invisibleUntilEarned": false, "fbEnabled": true, "appleEnabled": false, "googleEnabled": null, "id": "EGG_ACH02", "status": "AWARDED" } ] }, "status": 200 }
if false - you just get the
id
andstatus
of any achievements that are awarded.If the achievements had already been awarded, you'll get an empty array of
achievements
back.So anyway, try something like:
var achievementRes = gamificationService.awardAchievements(achievementIds, false);
and you should be good to go!
Thanks again for reporting this - we'll get that fixed up (which will probably mean we'll add an additional cloud-code method with the proper signature. This method will continue to work though!)
Cheers!
Paul.
-
D'oh - dueling support team responses!
-
Cheers guys. Thanks for the quick response!