Integrate challenge interaction in the game client
Overview
AccelByte Gaming Service (AGS) Challenge allows you to grant virtual rewards to the players upon completion of goals and challenges. This works by integrating with other services within AGS, such as AGS Identity and Access Management (IAM), AGS Statistics, AGS E-Commerce, and AGS Achievements, that will be used to define the goal’s requirements that players must achieve to earn virtual rewards.
This article provides information on how to integrate player challenge interactions and reward claiming using AGS Challenge with the AGS Game 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.
Evaluate the challenge
You are required to do this step if you use statistics and entitlements in your goal configurations. Otherwise, AGS Challenge will evaluate automatically.
Challenge evaluation is designated to compute the latest progress and status of the given goals. Calling this endpoint retrieves the most recent progress update. You can evaluate the challenge from the game client by using this code:
- Unreal Engine
- Unity
AccelByte::FMultiRegistry::GetApiClient()->Challenge.EvaluateChallengeProgress(
FVoidHandler::CreateLambda([]()
{
// on evaluate challenge progress success
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
UE_LOG(LogTemp, Warning, TEXT("[%d]: %s"),
ErrorCode, *ErrorMessage);
}));
string[] userIds = {
"userId1"
};
AccelByteSDK.GetServerRegistry().GetApi().GetChallenge().EvaluateChallengeProgress(userIds, result =>
{
if (result.IsError)
{
// Things to do when errors happen
Debug.Log($"Failed to EvaluateChallengeProgress {result.Error.Code} : {result.Error.Message}");
return;
}
Debug.Log($"EvaluateChallengeProgress Success");
});
Claim the reward
You can allow your player to claim rewards for a specific goal that were completed from the game client by using this code:
- Unreal Engine
- Unity
FAccelByteModelsChallengeRewardClaimRequest RewardClaimRequest{};
// You are able to retrieve reward IDs from this method: Challenge::GetRewards
RewardClaimRequest.RewardIDs = {"RewardId1"};
AccelByte::FMultiRegistry::GetApiClient()->Challenge.ClaimReward(RewardClaimRequest,
THandler<TArray<FAccelByteModelsChallengeReward>>::CreateLambda([]
(const TArray<FAccelByteModelsChallengeReward>& Response)
{
for (auto ChallengeReward : Response)
{
UE_LOG(LogTemp, Warning, TEXT("Item Name: %s Qty: %f"),
*ChallengeReward.ItemName, ChallengeReward.Qty);
}
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
UE_LOG(LogTemp, Warning, TEXT("[%d]: %s"),
ErrorCode, *ErrorMessage);
}));
// You are able to retrieve rewards IDs from this method: GetChallenge().GetRewards()
string[] rewardIds = {
"RewardId1"
};
AccelByteSDK.GetClientRegistry().GetApi().GetChallenge().ClaimReward(rewardIds, result =>
{
if (result.IsError)
{
// Things to do when errors happen
Debug.Log($"Failed to ClaimReward {result.Error.Code} : {result.Error.Message}");
return;
}
Debug.Log($"ClaimReward Success");
foreach (var item in result.Value)
{
Debug.Log($"Item Name: {item.ItemName} Qty: {item.Quantity}");
}
});
Claim all rewards
You can allow your player to claim all rewards from completed goals under a specific challenge from the game client by using this code:
- Unreal Engine
- Unity
FAccelByteModelsChallengeRewardClaimRequest RewardClaimRequest{};
// You are able to retrieve rewards IDs from this method: Challenge::GetRewards
RewardClaimRequest.RewardIDs = {"RewardCompletedId1", "RewardCompletedId2"};
AccelByte::FMultiRegistry::GetApiClient()->Challenge.ClaimReward(RewardClaimRequest,
THandler<TArray<FAccelByteModelsChallengeReward>>::CreateLambda([]
(const TArray<FAccelByteModelsChallengeReward>& Response)
{
for (auto ChallengeReward : Response)
{
UE_LOG(LogTemp, Warning, TEXT("Item Name: %s Qty: %f"),
*ChallengeReward.ItemName, ChallengeReward.Qty);
}
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
UE_LOG(LogTemp, Warning, TEXT("[%d]: %s"),
ErrorCode, *ErrorMessage);
}));
// You are able to retrieve rewards IDs from this method: GetChallenge().GetRewards()
string[] rewardIds = {
"RewardCompletedId1",
"RewardCompletedId2"
};
AccelByteSDK.GetClientRegistry().GetApi().GetChallenge().ClaimReward(rewardIds, result =>
{
if (result.IsError)
{
// Things to do when errors happen
Debug.Log($"Failed to ClaimReward {result.Error.Code} : {result.Error.Message}");
return;
}
Debug.Log($"ClaimReward Success");
foreach (var item in result.Value)
{
Debug.Log($"Item Name: {item.ItemName} Qty: {item.Quantity}");
}
});