Created
August 12, 2025 10:42
-
-
Save c64cosmin/f7ac9ae4be00badd4ab3422fb4b0611d to your computer and use it in GitHub Desktop.
SteamWorks initialization in Godot using GodotSteam GDExtension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extends Node | |
| var steam_powered: bool = false | |
| const STEAM_APP_ID = 480 | |
| enum Achievements { | |
| MY_AWESOME_ACHIEVEMENT0, | |
| MY_AWESOME_ACHIEVEMENT1 | |
| } | |
| func _init() -> void: | |
| OS.set_environment("SteamAppId", str(STEAM_APP_ID)) | |
| OS.set_environment("SteamGameId", str(STEAM_APP_ID)) | |
| func _ready() -> void: | |
| if not Steam.steamInit(STEAM_APP_ID): | |
| print("Steam failed to initialize") | |
| return | |
| steam_powered = true | |
| #this is some of the data available | |
| #print it to screen just to validate everything works ok | |
| var steam_id: int = Steam.getSteamID() | |
| var steam_username: String = Steam.getPersonaName() | |
| print(steam_id) | |
| print(steam_username) | |
| #you might need to reset the achievements if you are testing locally | |
| #delete these lines if you don't want to reset | |
| if OS.is_debug_build(): | |
| _reset_achievements() | |
| pass | |
| func trigger_achievement(achievement: Achievements): | |
| if not steam_powered: | |
| return | |
| Steam.setAchievement(Achievements.find_key(achievement)) | |
| Steam.storeStats() | |
| func _reset_achievements(): | |
| for key in Achievements.keys(): | |
| Steam.clearAchievement(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment