Display challenges in the game client
Overview
AccelByte Gaming Services (AGS) Challenge allows you to display active challenges for players to undertake and their progress towards completing those challenges. This article provides information on how to display the challenges and their progress, goals, and rewards that you've integrated with AGS Challenge using the AGS Gaming SDK.
Prerequisites
- The AGS Game SDK installed and configured into your Unreal or Unity project.
- An IAM client set up for your game, and access to that IAM client's ID and secret.
- Challenges integrated into your project with AGS Challenge.
Display challenge in the game client
After you have your challenge configurations set up, you can retrieve them to either display in the game client or access their code.
Retrieve and display all available challenges
You can retrieve all available challenge configurations and display them in the game client by using this code:
- Unreal Engine
- Unity
AccelByte::FMultiRegistry::GetApiClient()->Challenge.GetChall6enges(THandler<FAccelByteModelsGetChallengesResponse>::CreateLambda([]
(const FAccelByteModelsGetChallengesResponse& Response)
{
for (auto ChallengeData : Response.Data)
{
UE_LOG(LogTemp, Warning, TEXT("Challenge Name: %s Status: %s"),
*ChallengeData.Name, *FAccelByteUtilities::GetUEnumValueAsString(ChallengeData.Status));
// more various things to do with the challenge data
}
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
UE_LOG(LogTemp, Warning, TEXT("[%d]: %s"),
ErrorCode, *ErrorMessage);
}));
AccelByteSDK.GetClientRegistry().GetApi().GetChallenge().GetChallenges(ChallengeStatus.None, result =>
{
if (result.IsError)
{
// Things to do when Error happens
Debug.LogWarning($"Failed to GetChallenges {result.Error.Code} : {result.Error.Message}");
return;
}
Debug.Log($"GetChallenges Success");
foreach (var item in result.Value.Data)
{
Debug.Log($"Challenge Name: {item.Name} Status: {item.Status}");
}
});
Retrieve and display a specific challenge
You can retrieve a specific challenge configuration and display it in the game client by using this code:
- Unreal Engine
- Unity
const FString& ChallengeCode = TEXT("specific-challenge-code");
AccelByte::FMultiRegistry::GetApiClient()->Challenge.GetScheduledChallengeGoals(
ChallengeCode, THandler<FAccelByteModelsGetScheduledChallengeGoalsResponse>::CreateLambda([]
(const FAccelByteModelsGetScheduledChallengeGoalsResponse& Response)
{
for (auto ChallengeGoalData : Response.Data)
{
UE_LOG(LogTemp, Warning, TEXT("Goal Name: %s Description: %s IsActive: %hhd"),
*ChallengeGoalData.Name, *ChallengeGoalData.Description, ChallengeGoalData.IsActive)
}
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
UE_LOG(LogTemp, Warning, TEXT("[%d]: %s"),
ErrorCode, *ErrorMessage);
}));
const string challengeCode = "specific-challenge-code";
AccelByteSDK.GetClientRegistry().GetApi().GetChallenge().GetScheduledChallengeGoals(challengeCode, result =>
{
if (result.IsError)
{
// Things to do when Error happens
Debug.LogWarning($"Failed to GetChallengeGoals {result.Error.Code} : {result.Error.Message}");
return;
}
Debug.Log($"GetScheduledChallengeGoals Success");
foreach (var item in result.Value.Data)
{
Debug.Log($"Goal Name: {item.Name} Description: {item.Description} IsActive: {item.IsActive}");
}
});
Display player progress
You can retrieve the player's progression toward completing a challenge and display it in the game client by using this code:
- Unreal Engine
- Unity
const FString& ChallengeCode = TEXT("specific-challenge-code");
const FString& GoalCode = TEXT("specific-goal-code");
AccelByte::FMultiRegistry::GetApiClient()->Challenge.GetChallengeProgress(
ChallengeCode, GoalCode, THandler<FAccelByteModelsChallengeProgressResponse>::CreateLambda([]
(const FAccelByteModelsChallengeProgressResponse& Response)
{
for (auto ChallengeGoalProgressData : Response.Data)
{
UE_LOG(LogTemp, Warning, TEXT("Goal Code: %s Status: %s"),
*ChallengeGoalProgressData.GoalCode, *FAccelByteUtilities::GetUEnumValueAsString(ChallengeGoalProgressData.Status));
}
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
UE_LOG(LogTemp, Warning, TEXT("[%d]: %s"),
ErrorCode, *ErrorMessage);
}));
const string challengeCode = "specific-challenge-code";
const string goalCode = "specific-goal-code";
AccelByteSDK.GetClientRegistry().GetApi().GetChallenge().GetChallengeProgress(challengeCode, goalCode, result =>
{
if (result.IsError)
{
// Things to do when Error happens
Debug.LogWarning($"Failed to GetChallengeProgress {result.Error.Code} : {result.Error.Message}");
return;
}
Debug.Log($"GetChallengeProgress Success");
foreach (var item in result.Value.Data)
{
Debug.Log($"Goal Code : {item.ChallengeCode} Status: {item.Status}");
}
});