Set Up
The Set Up tutorial describes how to add your first game to ChilliConnect, integrate an SDK in to your game, add a new player, and record scores for that player against a leaderboard.
Add Your First Game
If you've not already done so, Sign Up to ChilliConnect. All metrics, players and game configuration such as leaderboards are stored against a game definition within ChilliConnect. When you first enter the ChilliConnect Dashboard, you'll be prompted to add your first game.
Press the Add Game button to create your first game in ChilliConnect
For now, the only detail required is your game name. But you can also add a logo to help you more easily identify the game within your ChilliConnect dashboard. After adding your game, you'll be taken to the Game View which displays your Game Logo, Name as well as your Game's GameToken
. Your GameToken
is what identifies your game when using the ChilliConnect API.
From the Game View, download the required SDK. Once the SDK has been downloaded, follow the instructions to add the SDK to your game. You'll need to supply the GameToken
from the Game View to the SDK. From this point on, the tutorial will assume you are using the Unity or iOS SDK. Once you've add the SDK to your game you can then start using the SDK to make use of all the functionality provided by ChilliConnect.
Create a New Player
For this tutorial, the first call we'll make will be to the Create Player method to create a new ChilliConnect player. The following code creates a new player with the DisplayName of "TestPlayer" and provides a call back that extracts the ChilliConnectID
and ChilliConnectSecret
from the response. Add the below code in to your project and then run:
Unity
using System;
using ChilliConnect;
var chilliConnect = new ChilliConnectSdk("<YourGameToken>", false);
var playerAccounts = chilliConnect.PlayerAccounts;
Action<CreatePlayerRequest, CreatePlayerResponse> successCallback = (CreatePlayerRequest request, CreatePlayerResponse response) =>
{
string ChilliConnectId = response.ChilliConnectId;
string ChilliConnectSecret = response.ChilliConnectSecret;
UnityEngine.Debug.Log("Player created with ChilliConnectId: " + ChilliConnectId);
};
Action<CreatePlayerRequest, CreatePlayerError> errorCallback = (CreatePlayerRequest request, CreatePlayerError error) =>
{
UnityEngine.Debug.Log("An error occurred while creating a new player: " + error.ErrorDescription);
};
var requestDesc = new CreatePlayerRequestDesc();
requestDesc.DisplayName = "TestPlayer";
playerAccounts.CreatePlayer(requestDesc, successCallback, errorCallback);
Unreal
iOS
CCPlayerAccounts *playerAccounts = chilliConnect.playerAccounts;
CCCreatePlayerResponseCallback successCallback = ^(CCCreatePlayerRequest *request, CCCreatePlayerResponse *response) {
self.chilliConnectId = response.chilliConnectId;
self.chilliConnectSecret = response.chilliConnectSecret;
NSLog(@"Player created with ChilliConnectId: %@", self.chilliConnectId);
};
CCCreatePlayerErrorCallback errorCallback = ^(CCCreatePlayerRequest *request, CCCreatePlayerError *error) {
NSLog(@"An error occurred while creating a new player: %@", error.errorDescription);
};
CCCreatePlayerRequestDesc *requestDesc = [CCCreatePlayerRequestDesc createPlayerRequestDesc];
requestDesc.displayName = @"TestPlayer";
[playerAccounts createPlayerWithDesc:requestDesc successCallback:successCallback errorCallback:errorCallback];
When the code executes a new player will be created within the ChilliConnect dashboard with the DisplayName of "TestPlayer". To verify this, you can use the Players section on your ChilliConnect dashboard to search for the player by the ChilliConnectID that was returned from the Player Create call.
(Note: in an actual game, you would usually persist the ChilliConnectID and the ChilliConnect Secret on the device and then check for these credentials on start up, rather than creating a new player each time. For the sake of simplicity, the tutorial will skip this step.)
Now that we've created a new player, we can use the returned ChilliConnectID
and ChilliConnectSecret
to Log In with this player using the Log In Using ChilliConnect method. Add the below code to your project to log the player in to ChilliConnect.
Unity
var playerAccounts = chilliConnect.PlayerAccounts;
Action<LogInUsingChilliConnectRequest, LogInUsingChilliConnectResponse> successCallback = (LogInUsingChilliConnectRequest request, LogInUsingChilliConnectResponse response) =>
{
UnityEngine.Debug.Log("Successfully logged in!");
};
Action<LogInUsingChilliConnectRequest, LogInUsingChilliConnectError> errorCallback = (LogInUsingChilliConnectRequest request, LogInUsingChilliConnectError error) =>
{
UnityEngine.Debug.Log("An error occurred while logging in: " + error.ErrorDescription);
};
var loginDesc = new LogInUsingChilliConnectRequestDesc(ChilliConnectId, ChilliConnectSecret);
playerAccounts.LogInUsingChilliConnect(loginDesc, successCallbackLogin, errorCallbackLogin);
Unreal
iOS
CCPlayerAccounts *playerAccounts = chilliConnect.playerAccounts;
CCLogInUsingChilliConnectResponseCallback successCallback = ^(CCLogInUsingChilliConnectRequest *request, CCLogInUsingChilliConnectResponse *response) {
NSLog(@"Successfully logged in!");
};
CCLogInUsingChilliConnectErrorCallback errorCallback = ^(CCLogInUsingChilliConnectRequest *request, CCLogInUsingChilliConnectError *error) {
NSLog(@"An error occurred while logging in: %@", error.errorDescription);
};
CCLogInUsingChilliConnectRequestDesc *desc = [CCLogInUsingChilliConnectRequestDesc logInUsingChilliConnectRequestDescWithChilliConnectId:self.chilliConnectId chilliConnectSecret:self.chilliConnectSecret];
[playerAccounts logInUsingChilliConnect:desc successCallback:successCallback errorCallback:errorCallback];
Once logged in we can now make requests that require a player to be authenticated. Note that the player remains authenticated for an hour, after which we will need to log in again. See the Player Accounts documentation for more details.
Posting a Leaderboard Score
Now that we have an authenticated player we can start using the rest of the Connect functionality. For this tutorial, we'll add a new leaderboard and post a score for the player to that leaderboard. Start by navigating to the Leaderboards view on your ChilliConnect dashboard
From here press the Add Leaderboard button create a new Leaderboard
Set the leaderboard name to "Tutorial Leaderboard" and leave the other fields as the default values and press Add Leaderboard. The ChilliConnect dashboard will define the Leaderboard Key based on the Name you provide - in this case, the key will be "TUTORIAL_LEADERBOARD". We can then use this key with the ChilliConnect SDK to add a score to this leaderboard.
Add the code below to your project to post a new score to the Tutorial Leaderboard.
Unity
var leaderboards = chilliConnect.Leaderboards;
Action<AddScoreRequest, AddScoreResponse> successCallback = (AddScoreRequest request, AddScoreResponse response) =>
{
UnityEngine.Debug.Log("The high score is now: " + response.Score);
};
Action<AddScoreRequest, AddScoreError> errorCallback = (AddScoreRequest request, AddScoreError error) =>
{
UnityEngine.Debug.Log("An error occurred while adding a score: " + error.ErrorDescription);
};
AddScoreRequestDesc requestDesc = new AddScoreRequestDesc(500, "TUTORIAL_LEADERBOARD");
leaderboards.AddScore(requestDesc, successCallback, errorCallback);
Unreal
iOS
CCLeaderboards *leaderboards = chilliConnect.leaderboards;
CCAddScoreResponseCallback successCallback = ^(CCAddScoreRequest *request, CCAddScoreResponse *response) {
NSLog(@"The high score is now: %@", @(response.score));
};
CCAddScoreErrorCallback errorCallback = ^(CCAddScoreRequest *request, CCAddScoreError *error) {
NSLog(@"An error occurred while adding a score: %@", error.errorDescription);
};
CCAddScoreRequestDesc *requestDesc = [CCAddScoreRequestDesc addScoreRequestDescWithScore:500 key:@"TUTORIAL_LEADERBOARD"];
[leaderboards addScoreWithDesc:requestDesc successCallback:successCallback errorCallback:errorCallback];
Run this code then refresh the Leaderboard view on your ChilliConnect dashboard. You should now see that the Leaderboard has a single score of 500.
Next Steps
This tutorial covered the basics of using ChilliConnect. From here you can explore our API documentation to find out what functionality is available from the SDK or look at our Metrics, Player Accounts, Leaderboards, and Push Notification in-depth guides to learn more about what you can do with ChilliConnect.