Steamworks API wrapper and cmake file

3rd party tools like asset generators, editors.
2 posts Page 1 of 1
Posts: 17
Joined: Fri Jul 14, 2017 2:19 am
by OTHGMars » Wed Jun 13, 2018 4:24 am
I've been working on updating AlterVerse to x64. After a couple times pulling in a branch, regenerating the project and having to link the Steamworks API to the build manually, I realized I needed a cmake file to eliminate that tedium. I placed that cmake file and my basic steamworks console wrapper into a branch that hopefully others can benefit from. If you're setting up a T3D build for steam, even if you don't use any of the code in this branch, the cmake file may save you some time.

I only use a couple functions from the steamworks API for getting the steam ID and display name for the current user. Thanks to @ Steve_Yorkshire sharing his achievement code here, I was able to get console functions added for achievements. Even so, this barely scratches the surface of the functions the Steamworks API makes available.

The files are located at This is setup as a Module and static engine class so all interaction is through script and no existing engine source files are changed.


You will need to download and extract the steamworks sdk and have an App ID for your game. The new cmake options are:


TORQUE_STEAMWORKS – Check this to have steamworks added to the build.
TORQUE_STEAMWORKS_APPID – Enter the App ID for your game.
TORQUE_STEAMWORKS_REQUIRED – If this is checked, a distributed build of your game will not launch without steam running. An attempt to launch the game from the exe will exit, launch the steam client, then relaunch the game through steam with a logged in user. See here and here for more details.
TORQUE_STEAMWORKS_SDKPATH – Point this to the sdk directory within the extracted steamworks package.

Once configured, cmake will add the include directory, link the library, copy the correct .dll or .so and generate your steam_appid.txt file.

Console Functions

Because the static engine class is named SteamAPI, all function calls through script must be prefixed with SteamAPI::. Unless you know you're running a distributed build and have steamworks set to required, you should call SteamAPI::isSteamRunning() before calling any of the other functions. See the Steamworks API Reference and the console docs with the function declarations for more info.

SteamAPI::isSteamRunning() - Returns true if Steam is running and the Steamworks API has been initialized.
SteamAPI::getUserId() - Returns the steam ID for the currently logged in steam user..
SteamAPI::getPersonaName() - Returns the local players name.
SteamAPI::areStatsLoaded() - Returns true if a requestCurrentStats command has successfully completed for the current user.
SteamAPI::requestCurrentStats() - Requests an asynchronous stats load.
SteamAPI::setAchievement(name) - Unlocks an achievement.
SteamAPI::clearAchievement() - Resets the unlock status of an achievement.
SteamAPI::storeStats() - Upload stats to steam.
SteamAPI::getNumAchievements() - Get the number of achievements.
SteamAPI::getAchievementName(index) - Gets the 'API name' for an achievement.
SteamAPI::getAchievement(name) - Gets the unlock status of the Achievement.
SteamAPI::getAchievementDisplayAttribute(name, key) - Get general attributes for an achievement.
SteamAPI::resetAllStats(achievementsToo) - Resets the current users stats and, optionally achievements.


See ... pp#L30-L56 for complete callback descriptions.

Example Script

function onSteamUserStatsReceived(%success)
   %text = "The user stats load " @ (%success ? "Succeeded" : "Failed");
   if (%success)

function onSteamGameOverlayActivated(%isActive)
   %text = "The steam game overlay is " @ (%isActive ? "Active" : "Inactive");

function listSteamAchievements()
   if (!SteamAPI::isSteamRunning())
      echo("Steam is not running");

   echo("Steam User: " @ SteamAPI::getPersonaName() @ ", Steam ID: " @

   if (!SteamAPI::areStatsLoaded())
      echo("No Stats Loaded Yet!");

   %numAchievements = SteamAPI::getNumAchievements();
   for (%i = 0; %i < %numAchievements; %i++)
      %apiName = SteamAPI::getAchievementName(%i);
      %achieved = SteamAPI::getAchievement(%apiName);
      %dispname = SteamAPI::getAchievementDisplayAttribute(%apiName, "name");
      %dispdesc = SteamAPI::getAchievementDisplayAttribute(%apiName, "desc");
      %hidden = SteamAPI::getAchievementDisplayAttribute(%apiName, "hidden");
      %achievedText = %achieved ? ", Unlocked" : ", Locked";
      %hiddenText = %hidden ? ", Hidden" : "";
      echo(%i SPC %apiName @ ": " @ %dispname @ ", " @ %dispdesc @ %hiddenText @ %achievedText);

if (SteamAPI::isSteamRunning())
Posts: 37
Joined: Thu Jun 23, 2016 12:02 pm
by damik » Wed Jun 13, 2018 11:15 am
:o thank you
2 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 0 guests