I am trying my first effort to try and build a game for steam … can anyone point to a great tutorial or sample code for that?
Do I need the Steamworks plugin… if not doing :
achievements, player stats, leaderboards, or showing in-app overlays?
Sorry for not knowing this process - but any direction or guidance is most appreciated.
Thanks
Bob
No, you don’t need the Steamworks plugin if you’re not planning to use achievements, player stats, or leaderboards.
That said, I have five puzzle games on Steam, and from my experience, adding those features really helps. A lot of players actively look for achievements and enjoy completing them, and if your game doesn’t have any, some people hesitate to buy it. I’m saying this from personal experience. Also, using Steam Cloud is a big plus. It allows players to sync their progress and access their save data from anywhere, which is something many users really appreciate.
At first, none of my games had the plugin implemented. But after getting a few reviews mentioning those features, I decided to learn how to integrate it, and now all of them use it. I’ve only implemented Steam Cloud in one game so far to test how the plugin behaves, and it seems to be working well … I haven’t received any negative feedback about it.
Also, you need to include in your build.settings:
[“plugin.steamworks”] =
{
publisherId = “com.coronalabs”,
supportedPlatforms = { win32=true }
},
In my games I do something like this: (for Steam Cloud)
local platform = system.getInfo( “platform” )
local steamCloud = {}
-- inside my Loading scene:
if platform == "win32" then
local steamworks = require( "plugin.steamworks" )
-- Steam Cloud functions
function steamCloud.checkStorageSpace()
local storageInfo = steamworks.getUserStorage()
if storageInfo then
local totalMB = storageInfo.totalBytes / (1024 * 1024)
local availableMB = storageInfo.availableBytes / (1024 * 1024)
local usedMB = totalMB - availableMB
print("Steam Cloud Storage:")
print("Total: " .. string.format("%.2f MB", totalMB))
print("Used: " .. string.format("%.2f MB", usedMB))
print("Available: " .. string.format("%.2f MB", availableMB))
-- Check if we have enough space for a save file
local saveDataSize = 1024 -- Estimated save file size in bytes
if storageInfo.availableBytes >= saveDataSize then
print("Sufficient storage space available")
return true
else
print("Warning: Low storage space!")
return false
end
else
print("Failed to retrieve storage information.")
return false
end
end
-- Before saving large data, check available space
function steamCloud.safeSavePlayerData(saveData)
local storageInfo = steamworks.getUserStorage()
if not storageInfo then
print("Cannot check storage - proceeding anyway")
else
local jsonData = json.encode(saveData)
local dataSize = string.len(jsonData)
if storageInfo.availableBytes < dataSize then
print("Error: Not enough cloud storage space!")
print("Need: " .. dataSize .. " bytes")
print("Available: " .. storageInfo.availableBytes .. " bytes")
return false
end
end
-- Proceed with save
return steamworks.writeFile("playerData.json", json.encode(saveData))
end
-- Complete load example with existence check
function steamCloud.safeLoadPlayerData()
if steamworks.fileExists( "playerData.json" ) then
local contents = steamworks.readFile( "playerData.json" )
if contents then
local saveData = json.decode(contents)
return saveData
end
end
return nil -- No data or failed to load
end
function steamCloud.deletePlayerData() -- ej: "playerData.json"
if steamworks.fileExists( "playerData.json" ) then
if steamworks.deleteFile( "playerData.json" ) then
print("Player data deleted from Steam Cloud.")
else
print("Failed to delete player data.")
end
else
print("No file to delete.")
end
end
-- to use from other scenes
function scene:getSteamCloud()
return steamCloud
end
end
-- then, from your game scene, you can do something like this:
if steamworks and steamworks.isLoggedOn then
local loadingScene = composer.getScene( "myLoadingScene" )
local steamCloud = loadingScene:getSteamCloud()
playerData = steamCloud.safeLoadPlayerData()
-- Example: you can use any variable from playerData just like a normal table:
local score = playerData.score
end
1 Like
@aclementerodrguez thank you much! Most kind to respond and it is most helpful!
I assume win32=true. if I am building with a pc-wndows, but I have a Mac - so maybe ‘Mac=true’ ?
And thanks for the sample code!
@aclementerodrguez I saw your 5 puzzle games on steam - really well done!
Do you make those same puzzle games as mobile apps on iOS or android?
Thank you!
Yes, I originally made the mobile versions first. You can check out the links on my website: https://alecgames.com
Thanks for the great help … I will check out that your site.
1 Like