Skip to content

List Broadcasts In-Game

This how-to starts a session with the player's timezone, retrieves the latest broadcast messages, and displays the data in your game.

Prerequisites

Start Session with Timezone Support (Optional)

To ensure broadcast messages are filtered and scheduled according to the player's timezone, you can optionally include timezone information when starting a player session.

This example uses Guest Login, but all platforms are supported.

using LootLocker.Requests;
using System;
public void StartSessionWithTimezone()
{
// Create session optionals to include timezone
LootLockerSessionOptionals optionals = new LootLockerSessionOptionals();
// For Windows, convert the system timezone to IANA format, read more in the section below
optionals.timezone = LootLockerTimezoneConverter.ConvertWindowsToIanaTzString(TimeZoneInfo.Local.StandardName);
// Start a guest session with timezone
LootLockerSDKManager.StartGuestSession((response) =>
{
if (response.success)
{
Debug.Log("Session started successfully with timezone: " + options.timezone);
// Proceed to retrieve broadcasts
}
else
{
Debug.LogError("Failed to start session: " + response.errorData.message);
}
}, optionals);
}

About Timezones

LootLocker uses the IANA standard for dealing with timezones. A timezone is written to a player's metadata with the key ll.timezone.

All platforms except Windows use IANA. If your game runs on Windows, you must convert the Windows timezone to an IANA timezone before sending it to LootLocker.

Use the utility class LootLockerTimezoneConverter to convert back and forth between IANA timezones:

// When sending a Windows Timezone to LootLocker:
LootLockerTimezoneConverter.TryConvertStringToIanaTzString(TimeZoneInfo.Local.StandardName);
// When reading an Iana timezone returned from LootLocker:
LootLockerTimezoneConverter.TryConvertStringToWindowsTzString(/*LootLockerIanaTimezoneReturnedFromMetadata*/);

Retrieve Broadcast Messages

Once you have an active session, retrieve broadcast messages that are currently live for your game and display them according to the player's preferred language.

using LootLocker.Requests;
using System.Collections.Generic;
public void GetBroadcastMessages()
{
string[] languagesToRetrieve = new string[] { "en", "sv" }; // English and Swedish
int limit = 10; // Number of items to fetch in this request
LootLockerSDKManager.ListBroadcasts(languagesToRetrieve, limit, (response) =>
{
if (response.success)
{
Debug.Log($"Retrieved {response.broadcasts.Length} broadcast messages");
foreach (var broadcast in response.broadcasts)
{
ProcessBroadcast(broadcast);
}
}
else
{
Debug.LogError("Failed to retrieve broadcasts: " + response.errorData.message);
}
});
}
// Example function for processing the broadcast
private void ProcessBroadcast(BroadcastMessage broadcast)
{
// If you need to treat languages differently, you can check the key of the current language
if (broadcast.languages.ContainsKey("en"))
{
LootLockerBroadcastLanguage currentLanguage = broadcast.languages["en"];
// The headline of the broadcast
Debug.Log($"Headline: {currentLanguage.headline}");
// The body of the broadcast
Debug.Log($"Body: {currentLanguage.body}");
// The language code of the broadcast
Debug.Log($"Language: {currentLanguage.language_code}");
// An URL to an image, add your own logic to download and display images in your UI
Debug.Log($"Image URL: {currentLanguage.image_url}");
// Custom action to take, for example starting a specific animation or instantiate a certain prefab
Debug.Log($"Action: {currentLanguage.action}");
// Process additional logic for extra localization keys, if any
foreach (var extraLocalization in currentLanguage.localizations)
{
Debug.Log($"Additional Localization - Key: {extraLocalization.Key}, Value: {extraLocalization.Value}");
}
}
}

Conclusion

You've retrieved broadcast messages from LootLocker and displayed their content in your game. Your game can now retrieve rich, localized broadcast messages that are properly scheduled according to player timezones, with support for multiple languages and custom localized fields like button text, subtitles, and other game-specific content.