Display rewards within your game
Overview
The AccelByte Gaming Services (AGS) reward service allows you to display rewards to the user in various ways. Displaying rewards within the game can provide players a clear goal to strive for. In this guide, you will learn how to display the rewards within the game.
Goals
- Explain how to use AccelByte SDK to display available rewards based on configurations that are set.
Prerequisites
- Access to the AGS Admin Portal.
- AccelByte Unreal or Unity SDK, including the permissions:
- Client ID
- Client Secret
- Access to AccelByte Platform service API documentation.
- Reward configuration should exist in the related namespace.
Displaying rewards
After you have your reward configurations are set up, you can choose to display a single reward or a list of rewards in your game UI.
Display a single reward
You can retrieve the reward information that you want to display using Reward ID or Code. This is suitable if you only want to display specific reward information to the players. Please follow the function below to retrieve the reward information:
Retrieve by reward ID
- Unreal Engine
- Unity
FString RewardId = TEXT("YourRewardId");
AccelByte::FRegistry::Reward.GetRewardByRewardId(RewardId,
THandler<FAccelByteModelsRewardInfo>::CreateLambda([&](const FAccelByteModelsRewardInfo& Result)
{
// Do something when successful
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something when failed
})
);
var reward = AccelByteSDK.GetClientRegistry().GetApi().GetReward();
string rewardId = "YourRewardId";
reward.GetRewardByRewardId(rewardId, result =>
{
if (result.IsError)
{
// Do something when failed
Debug.Log($"Error {result.Error.Code}: {result.Error.Message}");
return;
}
// Do something when successful
});
Retrieve by reward code
- Unreal Engine
- Unity
FString RewardCode = TEXT("YourRewardCode");
AccelByte::FRegistry::Reward.GetRewardByRewardCode(RewardId,
THandler<FAccelByteModelsRewardInfo>::CreateLambda([&](const FAccelByteModelsRewardInfo& Result)
{
// Do something when successful
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something when failed
})
);
var reward = AccelByteSDK.GetClientRegistry().GetApi().GetReward();
string rewardCode = "YourRewardCode";
reward.GetRewardByRewardCode(rewardCode, result =>
{
if (result.IsError)
{
// Do something when failed
Debug.Log($"Error {result.Error.Code}: {result.Error.Message}")
return;
}
// Do something when successful
});
Display list of rewards
You can also get a list of available rewards in your namespace and filter it. This is suitable if you want to let your players know all of the available rewards within the game. Please follow the function below to retrieve the list of rewards:
- Unreal Engine
- Unity
FString EventTopic = TEXT("YourEventTopic");
int32 Offset = 0;
int32 Limit = 1000;
EAccelByteRewardListSortBy SortBy = EAccelByteRewardListSortBy::REWARDCODE_ASC;
AccelByte::FRegistry::Reward.QueryRewards(EventTopic, Offset, Limit, SortBy,
THandler<FAccelByteModelsQueryReward>::CreateLambda([&](const FAccelByteModelsQueryReward& Result)
{
// Do something when successful
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something when failed
})
);
var reward = AccelByteSDK.GetClientRegistry().GetApi().GetReward();
string eventTopic = "YourEventTopic";
RewardSortBy sortBy = RewardSortBy.REWARDCODE_ASC;
reward.QueryRewards(eventTopic, sortBy, result =>
{
if (result.IsError)
{
// Do something when failed
Debug.Log($"Error {result.Error.Code}: {result.Error.Message}")
return;
}
// Do something when successful
});