Skip to content
Adam Biser edited this page Feb 9, 2023 · 21 revisions

Installing the Plugin

  1. Add the Plugin to the AGK IDE. Copy the SteamPlugin folder from inside the AGKPlugin folder of this project into the "Tier 1\Compiler\Plugins" folder where App Game Kit 2 is installed on your system.
  2. Create a steam_appid.txt file in your project folder. This file should only contain the app id for your game that was assigned by Steamworks.
  3. Copy the contents of AGKPlugin/GameFolder into your project folder.
  4. Make steam_api.dll (steam_api64.dll for 64-bit) and steam_appid files read only because the IDE will try to delete them both when your game closes. This step is only needed for running from the IDE. Running the project straight from its EXE does not do this.

Using the Plugin

The first thing that needs to be done is to import the plugin into the your project:

#import_plugin SteamPlugin As Steam

Once that is done, the Steam API needs to be initialized by calling Init(). It's worth noting that Init() also calls RequestStats() internally which starts the process of getting the user stats from Steam.

The Steam API relies upon asynchronous callbacks, so they must be given some time to process in the background of your application. To do so, be sure to call RunCallbacks() each time you call Sync(). Not doing so will cause some call results to never finish processing.

At the end of your program, you should call Shutdown() to shut down the Steam API.

On Linux

In order for your game to use this plugin, it will need to be executed using the shell script found in AGKPlugin/GameFolder. This script sets up the Steam environment variables needed to use the Steamworks API.

To develop using this plugin on Linux, copy AGKPlugin/AGK64SteamPlugin.sh into your AGKLinux folder and use it to start the IDE.

For Steam Users

Do not run the AGK IDE from the Steam client when using this plugin!
Doing so will cause the Steam API to find and use the IDE's app id instead of your project's app id.

Steam Version of AppGameKit Studio for Windows

As of a unaccounced update on January 24, 2022, the Steam version of AppGameKit Studio for Windows now utilizes the Steam DRM and the IDE must be run from the Steam client thus making this version incompatible with the plugin.

Try contacting TheGameCreators to request a DRM-free version of the IDE be added to your TheGameCreators account.

Debugging with the Plugin

In order to debug while using this plugin, place a copy of the files from AGKPlugin/GameFolder as well as your steam_appid.txt file into AppGameKit's interpreter folder.

For Classic, that folder is: "App Game Kit 2\Tier 1\Compiler\interpreters"

For Studio, that folder is: "AppGameKit Studio\media\interpreters"

Due to the nature of debugging, you shouldn't use RestartAppIfNecessary() and you'll need to change your steam_appid.txt file to match the project you're currently debugging.

Example

Here's a bare minimum example for using the plugin.

#import_plugin SteamPlugin As Steam

// RequestStats is already called within Init().
Steam.Init()
didStuff as integer
do
	Sync()
	Steam.RunCallbacks()
	if Steam.StatsInitialized()
		if not didStuff
			didStuff = 1
			GiveWinAndAchievement()
		endif
	endif
loop
Steam.Shutdown()

Function GiveWinAndAchievement()
	// Give the user a win.
	numGames as integer
	numWins as integer
	numGames = Steam.GetStatInt("NumGames")
	numWins = Steam.GetStatInt("NumWins")
	// GetStatInt will set the error flag if there's a problem.
	if GetErrorOccurred()
		Message("ERROR: " + GetLastError())
	else
		inc numGames
		inc numWins
		Steam.SetStatInt("NumGames", numGames)
		Steam.SetStatInt("NumWins", numWins)
		// Give the win one game achievement.
		Steam.SetAchievement("ACH_WIN_ONE_GAME")
		// Store all stats online.
		// Will also notify user of achievement.
		Steam.StoreStats()
	endif
EndFunction

Variable Types

Booleans

Since AGK does not have a boolean variable type, the plugin uses integers where 0 represents false and 1 represents true.

CSteamID

Since plugins cannot return class instances or have them as parameter values, the plugin maintains an internal array of the CSteamID objects and returns a 1-based index position that the AGK code can use instead. These index positions are also called handles within the command reference.

A CSteamID of 0 represents k_steamIDNil, which is a null and invalid steam ID and is useful for determining the success of some commands.