Skip to content

Search

Dokumentáció

Steam

Steamworks from Balaur Script: the steam modules in every desktop build, a game that runs without Steam, balaur export --steam, and callbacks.

Ezen az oldalon

Every desktop build of the engine has Steam in it, and so does the editor. Valve's Steamworks SDK is loaded at run time, from the steam_api library beside the game, when the Steam client runs it.

  • Without that library or the client, the game runs as before. Every steam_* call answers nil, and a call that answers later answers unsupported.
  • steam::is_loaded() says which case you are in.
  • Where Steam is loaded, platform::sign_in and platform::identity answer through it. Platform services says what answers each call elsewhere.

The modules

Each Steamworks interface is a module: Valve's method names in snake case. SteamUser()->GetSteamID() is steam_user::get_steam_id(), and SteamUserStats()->GetAchievement is steam_user_stats::get_achievement. The script modules reference lists every one.

  • steam holds is_loaded, Valve's enums and constants under their own names, and the EVENT_* kinds.
  • A call Valve answers later returns an id. task::wait on it answers a map whose kind is an EVENT_* constant, with the callback's fields and failed.
  • Callbacks nobody asked for arrive as the steam_event event, on a node that called events::listen(node, "steam_event").
// scripts/steam_hooks.bs
pub class SteamHooks {
    node: Node,
}

impl SteamHooks {
    pub async fn init() {
        if !steam::is_loaded() {
            log::info("no Steam here; the game plays on without it");
            return;
        }
        events::listen(self.node, "steam_event");

        let name = steam_friends::get_persona_name().or("player");
        log::info("playing as {name}");

        let first = steam_user_stats::get_achievement("ACH_FIRST_RUN");
        if first != nil && !first.unwrap().achieved {
            steam_user_stats::set_achievement("ACH_FIRST_RUN");
            steam_user_stats::set_stat_int32("runs", 1);
            steam_user_stats::store_stats();
        }

        let count = await task::wait(steam_user_stats::get_number_of_current_players());
        if count["kind"].as_str() == steam::EVENT_NUMBER_OF_CURRENT_PLAYERS {
            log::info("{count["players"]} playing now");
        }
    }

    pub fn on_steam_event(e: any) {
        if e["kind"].as_str() == steam::EVENT_USER_STATS_STORED {
            log::info("stats stored");
        }
    }
}

Exporting for Steam

A plain export ships no Valve file. A Steam build is the same export with one flag:

balaur export . --target windows-x64 --steam
  • --steam copies Valve's steam_api beside the game, inside Contents/MacOS in a .app, signed there with the game's identity.

  • It needs the AppID Steamworks gave the game, in project.toml:

    [steam]
    app_id = 480
  • --steam --dev also writes the AppID to steam_appid.txt beside the game, so it starts without the Steam client. A release leaves it out: the client names the app.

Steam takes 64-bit Windows, macOS and 64-bit Linux. Forge builds the Steam build beside the plain one and uploads it to your depots; see the Forge Steam guide.

Biztos vagy benne?