Last updated 5 months ago
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"); 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() { }