Use Metadata to Store Additional Information
Last updated
Last updated
In this scenario, the player has had the opportunity to write / select their country to be displayed on the Leaderboard.
string leaderboardKey = "my_leaderboard";
int score = 1000;
string metadata = "country:" + PlayerPrefs.GetString("PlayerAssignedCountry"); // Replace PlayerPrefs.GetString("PlayerAssignedCountry") with an existing way of getting the configured country for the player in your game
LootLockerSDKManager.SubmitScore("", score, leaderboardKey, metadata, (response) =>
{
if (!response.success) {
Debug.Log("Could not submit score!");
Debug.Log(response.errorData.ToString());
return;
}
Debug.Log("Successfully submitted score!\n with metadata: " + metadata);
});
The header file for the SubmitScoreHandler should look like this:
#pragma once
#include "CoreMinimal.h"
#include "LootLockerSDKManager.h"
DECLARE_DELEGATE_OneParam(FOnSubmitScoreResponse, FLootLockerSubmitScoreResponse);
class YOURPROJECTNAME_API SubmitScoreHandler
{
public:
SubmitScoreHandler();
void SubmitScore(int score);
~SubmitScoreHandler();
private:
FString metadata;
FString leaderboardKey;
void OnSubmitScoreResponse(FLootLockerSubmitScoreResponse Response);
};
The cpp file should look something like this:
#include "CountrySubmit.h"
CountrySubmit::CountrySubmit()
{
}
void SubmitScoreHandler::SubmitScore()
{
metadata = "Country:" + FunctionWhichGetsCountry();
ULootLockerSDKManager::SubmitScore("",
leaderboardKey,
score,
metadata,
FOnSubmitScoreResponse::CreateUObject(this, &CountrySubmit::OnSubmitScoreResponse));
}
void SubmitScoreHandler::OnSubmitScoreResponse(FLootLockerSubmitScoreResponse Response)
{
if (!Response.success) {
UE_LOG(LogTemp, Log, TEXT("Error: %d"), Response.ErrorData.Message);
return;
}
UE_LOG(LogTemp, Log, TEXT("Score submitted successfully. Rank: %d"), Response.rank);
}
CountrySubmit::~CountrySubmit()
{
}
var metadata : String = "country: " + PlayerInformation.GetPlayerAssignedCountry() # Replace PlayerInformation.GetPlayerAssignedCountry() with an existing method that gets the configured country for the player in your game
var leaderboardKey : String = "my_leaderboard"
var score : int = 1000
var response = await LL_Leaderboards.SubmitScore.new(leaderboardKey, score, "", metadata).send()
if(!response.success) :
# Request failed, handle errors
pass
else:
# Request succeeded, use response as applicable in your game logic
pass