Godot 4 · GDScript · Setup & session
set_controller
Initializes the client and starts the session lifecycle. Call once at startup.
Signature
set_controller(game_id: String, api_key: String) -> voidWhat it does
Configures the client, loads any persisted player identity from disk, and arms the session lifecycle. From here the plugin starts the session and keeps it renewed on its own, so your game only reacts to the signals. Every typed signal is also mirrored on the catch-all api_event(event_name: String, payload: Dictionary) signal (payload = { arg_name: value }), useful for logging or debug consoles.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| game_id | String | required | Your game's GAME_ID from the Gamdato dashboard. |
| api_key | String | required | Your API_KEY from the dashboard. Never hardcode or commit it: read it from an environment variable or a gitignored config file. |
How to call it
Call exactly once at startup, after set_save_secret() (if you use it) and before set_leaderboard(). Connect session_started and tables_loaded first so you know when the client is ready.
Returns: void (the session starts asynchronously; listen to session_started).
Example
func _ready() -> void:
Gamdato.session_started.connect(_on_connected)
Gamdato.tables_loaded.connect(_on_ready)
Gamdato.set_controller("YOUR-GAME-ID", OS.get_environment("GAMDATO_API_KEY"))
Gamdato.set_leaderboard(["scores_normal", "scores_hard"])
func _on_connected(player_id: String, player_name: String, is_new: bool) -> void:
print("session ok: %s (new=%s)" % [player_name, is_new])Use cases
- Boot the backend when your game launches.
- Re-authenticate a returning player automatically, since their identity is restored from disk.