How do I Save game using new File System?

Not favoritedFavorited Favorited 0 favourites
  • 8 posts
From the Asset Store
Kids Game
$49 USD
New Sounds Added Update: 115 new sound effects added for no additional cost!
  • Hi everyone,

    I’m working on a simple platformer in Construct 3 and need some help with implementing a save system using the new File System features.

    Here’s what I have so far:

    • Currently, I’m using the standard save system in Construct 3, and the game saves to a save slot.
    • If player overlaping a save point and press S - that will save the game.
    • If the player collides with spikes, they die, and the game reloads from the last save point.

    What I’m trying to achieve: I want to move away from the default save system and instead save the game to a folder of my choice, such as:

    C:\Users\User\Saved Games

    The reason for this change is to use Steam Cloud, enabling me to sync saves between my Windows PC and Steam Deck.

    I’ve created an example where you can see the code in action. You can check it out here:

    https://drive.google.com/file/d/1b_gROETrNmLasAgryC0HaxnppI6B6Jsh/view?usp=sharing

    I’m unsure how to configure the File System to let the me choose or define the save folder. Any advice, examples, or suggestions on how to achieve this would be much appreciated. Looking forward to your feedback! 😊

    Thanks in advance for your help!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi Everyone,

    So I made some progress!

    I figured out how to save to a custom folder using NW.js. Here's an updated example—it works perfectly fine:

    drive.google.com/file/d/1uJ5eoSmSMkeTfc73JVw9ke82KAwC8vcc/view

    However, the size of this simple game is very big (135MB zipped, unzipped is 288MB). So… I would love to achieve the same functionality using the new File System object and Windows WebView2 export instead.

    If anyone has any ideas or examples on how to do this, please let me know! 🙏

  • With the File System object in a Windows WebView2 export, it can be done like this:

    • When you want to save (e.g. on pressing 'S'), use the Save to JSON system action
    • In the system trigger On save complete, use the File System action Write text file to write to something like picker tag "<documents>", folder path "mygame/mysave.json", with text set to the system expression SaveStateJSON

    That will then save the current game state to a path like Documents/mygame/mysave.json in a desktop exporter like Windows WebView2.

    To load you can do what amounts to the same thing in reverse:

    • When you want to load (e.g. on pressing 'L'), use the File System action Read text file to read from the same details (i.e. picker tag "<documents>", folder path "mygame/mysave.json") - but use a file tag like "loading"
    • In the File System trigger On file operation complete, enter the file tag "loading" again - this triggers when the save file has been loaded. Then use the system action Load from JSON to load the expression FileSystem.FileText.

    That's the basic pattern - once you get that working it shouldn't be too hard to vary it for multiple saves (just change the file path). You could also use List content to find the existing save files.

  • Thanks for the advice Ashley, that totally works!

    Here's an example file that demonstrates this in action:

    https://drive.google.com/file/d/1mnY1Qz9ltXWAuC6-R2TYTah1VVfVnJk3/view?usp=sharing

  • I’ve been experimenting with the File System plugin in Construct 3, but it seems that the File System plugin doesn’t work when I do a regular preview in Construct 3 (probably due to browser limitations). It works perfectly fine when I export to Windows Web View 2 file.

    Is there a way to check if the File System plugin is active or available during runtime? If the File System isn’t accessible, I’d like to create a condition where the game loads data from a Save Slot instead of from the file system.

    If anyone knows how to implement this kind of fallback mechanism, I’d really appreciate your guidance.

  • Is there a way to check if the File System plugin is active or available during runtime?

    That's what the Desktop features supported condition is for.

  • Hi Ashley,

    Thanks so much for your help! That works great 😊 I’ve updated the file, so here’s a working example for everyone:

    https://drive.google.com/file/d/1mnY1Qz9ltXWAuC6-R2TYTah1VVfVnJk3/view

  • With the File System object in a Windows WebView2 export, it can be done like this:

    • When you want to save (e.g. on pressing 'S'), use the Save to JSON system action
    • In the system trigger On save complete, use the File System action Write text file to write to something like picker tag "<documents>", folder path "mygame/mysave.json", with text set to the system expression SaveStateJSON

    That will then save the current game state to a path like Documents/mygame/mysave.json in a desktop exporter like Windows WebView2.

    To load you can do what amounts to the same thing in reverse:

    • When you want to load (e.g. on pressing 'L'), use the File System action Read text file to read from the same details (i.e. picker tag "<documents>", folder path "mygame/mysave.json") - but use a file tag like "loading"
    • In the File System trigger On file operation complete, enter the file tag "loading" again - this triggers when the save file has been loaded. Then use the system action Load from JSON to load the expression FileSystem.FileText.

    That's the basic pattern - once you get that working it shouldn't be too hard to vary it for multiple saves (just change the file path). You could also use List content to find the existing save files.

    Thanks Ashley! I was looking for this since today's stable update. Thanks to this, I've managed to load the old local storage and use it to save with the new file system (with json) so that my playerbase won't lose data during the transition from NW.js to WebView 2. (I haven't tested it on Steam yet but I can confirm its working locally)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)