How to Integrate Steamworks API with Harlowe and Tweego

If you are requesting technical assistance with Twine, please specify:
Twine Version: Tweego v2.1.1
Story Format: Harlowe v3.3.1

Has anyone successfully integrated Steamworks (especially the Steam Achievements API) with Twine/Twee/Harlowe? Every example I find online is how to integrate the Steamworks API with Unity.

1 Like

I will assume you mean using JavaScript and the Steamworks Web API to access Steamworks features.

Harlowe has been deliberately designed to limit an Author’s ability to use JavaScript to enhance either their project, or the core functionality of the story format’s engine. And as Harlowe has no documented JavaScript API for accessing the internals (History, Variables, etc) of its engine, you will likely need to read the Harlowe project’s source code and resort to “hacks” to gain access to any of those internals.

If you haven’t progress far in your project and really want to use JavaScript to enhance it, then you may want to consider changing to one of the other story formats that support using JavaScript to do that.

I’m pretty early in the project so I could switch if needed. Do you know of any examples of integrating the Steamworks API with one of the other Story Formats?

I see that Harlowe has Custom Macros now. Would it be possible to use these to interface with the Steamworks API? Would something like the Greenworks project help facilitate this?

I assume your goal here is to sell your Twine game on Steam, and to support Steam achievements.

To do that, you’ll have to build an Electron app, and use something like Greenworks to integrate with it. Greenworks is no longer supported as of 2022, but https://github.com/ceifa/steamworks.js looks pretty compelling.

Creating and building an Electron app can be pretty daunting. You might start by availing yourself of Emilia Lazer-Walker’s Twine App Builder. https://github.com/lazerwalker/twine-app-builder The Twine App Builder doesn’t integrate with Greenworks or steamworks.js out of the box, but if you’re an experienced JavaScript developer, it seems plausible that you could integrate steamworks.js with Twine App Builder with some hard work.

(If you did it, I bet Emilia would be happy to accept a pull request to add Steam support to Twine App Builder.)

As for Story Formats, Snowman is specifically designed to let you write arbitrary JavaScript. If you had a working Twine App Builder that supported steamworks.js, you could use Snowman templates like this:

<%
const steamworks = require('steamworks.js')

// You can pass an appId, or don't pass anything and use a steam_appid.txt file
const client = steamworks.init(480)

// Print Steam username
console.log(client.localplayer.getName())

// Tries to activate an achievement
if (client.achievement.activate('ACHIEVEMENT')) {
    // ...
}
%>

Notably, the Steamworks Web API is probably not what you want. In that API, you’d have to operate a web server that can accept web requests. On that server, you’d store a secret key that you’d use to authenticate with Steam. With that set up, your Steam game could contact your web server, send the user’s Steam ID to your web server, and then have your web server use the SetUserStatsForGame API to register an achievement.

But to do that, you’d need to get the user’s numeric Steam ID, which, itself, would require you to integrate with Steamworks. At that point, you might as well just activate the achievement yourself, rather than incorporating an unnecessary web server.

1 Like

Correct, my goal is to sell the game on Steam and integrate Steam Achievements. I already have my Steamworks account, and I’ve been using Twine App Builder to build the app. I’ll be experimenting with just getting that basic app on steam this week with the builds to get a handle on that. I’ve been using many of Emilia’s projects on GH.

The reason I moved to Harlowe was because it has been updated frequently and is the official/default for the Twine app, but I can look at migrating my code to Snowman. I don’t have that much stuff so far so it shouldn’t be too bad. This is why I wanted to test features like this early so I could make the switch without already having a huge pile of code to convert. :rofl:

Good to know on the Steamworks API vs Steamworks Web API. I was wondering what the differences were.

Thanks for the guidance!

Tasks

  1. Move to Snowman storyformat
  2. Fix any necessary script/passage changes
  3. Test integrating steamworks.js with Twine App Builder

It occurs to me that the only Twine game on Steam that I’m aware of that has achievements is Open Sorcery.

There’s no way to search for Twine games, but Steam will tell you which games have achievements or not, and all of the other Twine games on Steam that I could think of don’t have achievements.

Just so you know what you’re in for, I predict that you’re about to sign up for something quite difficult!

Thanks for the link! I was also trying to see if there were any Twine games that had achievements as well, but I didn’t find anything.

Yeah, once I wasn’t able to find anything online about setting up Steamworks with Twine, I knew I was in for trouble. Haha. We’ll see how far I get.