How many players are online?
Knowing how many players are currently playing your game is something that almost everyone wants to know. It's always great to see player counts climbing, especially after new updates or announcements.
But how can you track this? You could build your own tracking system, but that's time-consuming and complex - you've got a game to build! That's why we built Talo, a game backend platform that makes it easy to understand player behaviour and gain oversight over your game's data. In this tutorial, we'll show you how to use Talo to track player counts in your Godot game.
Online player counts with Talo
Talo makes it easy to segment your players using player groups. You can use player groups to create distinct buckets of players. For example, in this tutorial, you'll use player groups to check for players with a custom "online" property.
When your Godot game starts, you'll identify the player and set the "online" property to true
. When they exit the game, you'll set it to false
. Using Talo's new pinned groups feature in the dashoard, you can see the number of players in the "online" group in real-time.
Setup the Talo Godot plugin
You need to start by setting up the Talo Godot plugin. You can do this by downloading the plugin from the Godot Asset Library (or by searching "Talo Game Services" in the AssetLib
tab of the Godot editor). You can also find the latest version of the plugin on itch.io.
Once you've downloaded the plugin, import it (typically you want to install plugins under the addons
folder) and enable it in the Project > Project Settings > Plugins
window.
You can now run your game - this will create a settings.cfg
asset inside the folder where you installed the plugin - you'll need this later. To learn more about how to configure Talo, including how to configure your self-hosted version, check out the docs.
Generating an access key
Next you need to generate an access key for your game. Visit the Talo dashboard, login or create an account (and confirm your email address). Once logged in, create a new game (if you need to) and visit the Access Keys page.
Once there, choose the scopes available to your access key. For this tutorial, you'll need the read:players
and write:players
scopes. Create your access key and copy it into the access_key
field of the settings.cfg
.
Creating your group
Talo players can have properties (known as props) that persist between sessions. As long as you know who the player is, you can set and get these properties. Player groups are able to read these properties and adjust the group's members accordingly.
To create your group, click the Services
dropdown and go to Groups
. Create a new group where you check for the online
prop being equal to true
. After creating your group you can pin it to your dashboard so you can see the online player count from the dashboard homepage.
Setting up the game logic
All you need for this tutorial is a scene with a single root node, for example a Node2D
. Attach a script to your root node with the following content:
extends Node2D
@export var username: String = "username"
func _ready() -> void:
# prevent Talo from exiting before our online prop logic runs
Talo.settings.set_value("", "handle_tree_quit", false)
Talo.players.identified.connect(_on_identified)
# identify who the player is
Talo.players.identify("username", username)
func _on_identified(_player: TaloPlayer) -> void:
# set the prop now that we know who the player is
await Talo.current_player.set_prop("online", "true")
func _notification(what: int):
match what:
NOTIFICATION_WM_CLOSE_REQUEST:
# update the prop before quitting
await Talo.current_player.set_prop("online", "false")
get_tree().quit()
This script does the following:
- Sets the Talo
handle_tree_quit
property tofalse
. By default Talo will listen for theNOTIFICATION_WM_CLOSE_REQUEST
notification to run cleanup operations and then exit. However in this case, the online property should be updated first before the game exits. - Identifies the player using the
username
service. The player's username can be customised using the export variable. - Once the player is identified, their
online
property is set totrue
. At this point they should be in the "Online players" group you created earlier. - If the player closes the game, their
online
property is set tofalse
and the game is exited. They will no longer be part of the "Online players" group.
Testing the online player count
You can now open your game, go to the dashboard, and see the "Online players" group count is 1. If you close the game, it will reset back down to 0. As mentioned earlier, the group can be pinned to your dashboard so you can always see the online player count when visiting the Talo dashboard.
Making oversight easy
Talo is designed to be extremely flexible in the way it provides observability and oversight to you. You don't need to spend hours building your own tools when you can just use Talo and the customisable groups to drill down into specific player behaviours.
If you're building a game and you want more oversight over it, come and join our Discord community or follow us on GitHub to keep up to date with how we're improving Talo to make game development fun, easy and observable.
Build your game faster with Talo
Don't reinvent the wheel. Integrate leaderboards, stats, event tracking and more in minutes.
Using Talo, you can view and manage your players directly from the dashboard. It's free!
Get started
More from the Talo Blog
Exploring Talo’s new Caddy self-hosting template
A breakdown of Talo’s latest Caddy-based self-hosting option, plus a look at other self-hosting templates available for your game.
Changelog: group updates + new Godot game save demo
All the highlights from Talo’s October 2024 releases across the dashboard, backend, Godot plugin and Unity package.
How to load and save game state using Godot
A quick and easy example of how to use Talo Game Saves to handle saving and loading scenes in your Godot game even when players are offline.
Steamworks authentication is now available
You can now identify Steam players and sync them up with Talo. Plus, an overview of new releases this month.