Creating an Achievement


GameSparks Achievements support the rewarding of players for accomplishments within a game and are highly configurable with respect to both rewards and the criteria used to control when rewards are delivered:

In this section you'll learn how to award an Achievement using custom Cloud Code. To do this, you'll need to:

Creating an Achievement

1. First, navigate to Configurator > Achievements.

2. Click Add. The Add Achievement page opens.

3. Enter the details for the new Achievement:

Other Configuration Options? All other Achievement configuration options that are not listed above can be left as default for this tutorial.

4. Click Save and Close. The Add Achievement page closes and you are returned to the Achievements page where your new Achievement is added.

More on Achievements? For an in-depth guide about Achievements click here.

Creating an Event

Following creation of an Achievement, you'll need to create a new Event. You can reference back to Creating a Leaderboard if you need to refresh on how to do this:

Attaching Cloud Code to the Event

After you've created and configured the Award Achievement Event, you'll need to attach some custom Cloud Code to it to award the Achievement when the Event is called.

1. Navigate to Configurator > Cloud Code > Events > Award_Achievement. The Cloud Code editor opens for the Event.

2. In the Cloud Code editor, add your custom Cloud Code for this Event.

3. Click Save.

    var player = Spark.getPlayer();


The Achievement is now fully configured to be awarded!

Running the Event in the Test Harness

1. Since everything is set up, you now need to navigate to the Test Harness and authenticate with one of the players you have previously registered.

2. At this point, the Achievement you've configured awards some currency and you need to validate that the player currently doesn't have any currency associated with their account. To do this, you'll need to select Player tab and send an AccountDetailsRequest:

3. Now you'll need to send the LogEventRequest for the Event you've configured earlier and using the Award_Achievement Short Code you gave it as the eventKey:

4. Finally, you can validate that the currency amounts were awarded by calling the AccountDetailsRequest again:

SDK Instructions