Godot 4 (web)
The Godot addon adds a Gamealia autoload that calls the JavaScript SDK through JavaScriptBridge. Godot 4.3 or newer, Web export.
Install
- Run
gamealia init --writein the Godot project folder (or ask your assistant), which copiesaddons/gamealia/. Or copy that folder by hand. - Enable Gamealia in Project → Project Settings → Plugins. This registers the
Gamealiaautoload. In Project → Export → Web → HTML → Head Include, add:
<script src="https://gamealia.app/sdk/v1.js"></script>- Export for Web and upload the export folder, with the exported page renamed to
index.html. A threaded export (SharedArrayBuffer) needs the listing's isolation set tocoop-coep.
Use
Calls that return a value are coroutines: use await.
func _ready() -> void:
Gamealia.ad_started.connect(func(): get_tree().paused = true)
Gamealia.ad_finished.connect(func(_r): get_tree().paused = false)
Gamealia.paused.connect(func(): get_tree().paused = true)
Gamealia.resumed.connect(func(): get_tree().paused = false)
var info := await Gamealia.init()
# info.locale: "es", "en", ...
var save := await Gamealia.data_load()
if save.ok:
progress = save.data.get("progress", {})
# else: could not read the save; do not overwrite it
Gamealia.loading_stop() # required, once the game is playable
func start_level() -> void:
Gamealia.gameplay_start()
func game_over() -> void:
Gamealia.gameplay_stop()
await Gamealia.request_midgame()
show_game_over()
func watch_ad_for_life() -> void:
var ad := await Gamealia.request_rewarded()
if ad.rewarded:
lives += 1
A complete example is in the addon's sample/main.gd.
API
| GDScript | JavaScript |
|---|---|
init() -> Dictionary, init_result, locale, environment, device, signal init_done(result) | init() |
is_available() -> bool | the page loaded the SDK |
loading_start(), loading_stop(), gameplay_start(), gameplay_stop(), happy_time() | game.* |
request_midgame(), request_rewarded() → {kind, shown, rewarded}; signals ad_started, ad_finished(result) | ad.* |
get_user() (Dictionary or null), get_token() ("" for guests), request_login() | user.* |
data_load() → {ok, data, error}, data_get(key), data_set(key, value) -> bool, data_remove(key), data_clear() | data.* |
get_join_code() -> String, invite_link(code), show_invite(code), publish_room(room), unpublish_room() | room.* |
set_presence(text) | presence.setStatus() |
signals paused, resumed, muted, unmuted, user_changed(user), room_join(code) | on(event) |
- Audio: with
auto_mute_audio(defaulttrue) the Master bus is muted while an ad plays. - Saves: values are JSON, so numbers come back as
float. 1 MB per player and game. - Rooms:
publish_roomtakes a Dictionary withcode,name,players,maxandinProgress.
Outside the web
In the editor, on desktop or mobile exports, and in a web page without the SDK, every call works locally: init() returns an environment: "mock" result, ads return "not shown" and data is saved to user://gamealia_data.json.
Common autotest failures
sdk_loaded: the Head Include is missing.entry: the exported page is not namedindex.html, or you uploaded the parent folder.engine_integrity: the.js,.wasmand.pckfiles of the export must all be uploaded.