Displaying 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
- Retrieve by reward ID in Unreal Engine
- Retrieve by reward ID in Unity
FString RewardId = TEXT("YourRewardId");
AccelByte::FRegistry::Reward.GetRewardByRewardId(RewardId,
THandler<FAccelByteModelsRewardInfo>::CreateLambda([&](const FAccelByteModelsRewardInfo& Result)
{
/* do something when succeed */
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
/* do something when failed */
})
);
string rewardId = "YourRewardId";
AccelBytePlugin.GetReward().GetRewardByRewardId(rewardId, result =>
{
if (result.IsError)
{
/* do something when failed */
}
else
{
/* do something when succeed */
}
});
Retrieve by reward code
- Retrieve by reward code in Unreal Engine
- Retrieve by reward code in Unity
FString RewardCode = TEXT("YourRewardCode");
AccelByte::FRegistry::Reward.GetRewardByRewardCode(RewardId,
THandler<FAccelByteModelsRewardInfo>::CreateLambda([&](const FAccelByteModelsRewardInfo& Result)
{
/* do something when succeed */
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
/* do something when failed */
})
);
string rewardCode = "YourRewardCode";
AccelBytePlugin.GetReward().GetRewardByRewardCode(rewardCode, result =>
{
if (result.IsError)
{
/* do something when failed */
}
else
{
/* do something when succeed */
}
});
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:
- Display list of rewards in Unreal Engine
- Display list of rewards in 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 succeed */
}),
FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
/* do something when failed */
})
);
string eventTopic = "YourEventTopic";
RewardSortBy sortBy = RewardSortBy.REWARDCODE_ASC;
AccelBytePlugin.GetReward().QueryRewards(eventTopic, sortBy, result =>
{
if (result.IsError)
{
/* do something when failed */
}
else
{
/* do something when succeed */
}
});