Can I check if a savegame exists?

0 favourites
  • 9 posts
  • In my game I have the option to continue playing. This is provided with a button in the main menu.

    I don't see any option to check if a savegame actually exists however. Is this possible? I use "saveGameToSlot" und "loadGameFromSlot" to save the game. Is there anything that I can use to check for a savegame?

    A workaround could be that I start a new game if the loading fails, but I rather not display the continue button at all if the game was not saved before.

  • I achieved this with a value saved to local storage (check manual). When you launch the app you check if a certain key exists in local storage, if not then this assumes the player has not saved before and you give them the new game flow. If the key exists then this means they have a save game and you present the slots as needed. To set the key you set it in local storage the first time a user saves.

  • I had the same idea, but I think that will not work if the player changes the browser, will it?

    As far as I know, the savegames of webgames are linked to the browser, but the local storage data is saved on the device, independend of the browser. Or is it also connected to the browser?

  • You are correct that changing browser would be different data

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Then I guess I could use that mechanic, but start a new game in case the loading fails.

    I wonder why the feature does not exist, I can't be the first one to need it?!

  • Isn't that what you had originally and you said it's no good ? I'm not sure if there is a condition for load game failed.

    It's generally known that if you change browser it's new data on a web game, or if you uninstall the mobile app then it wipes the local data.

  • I mean I could make it as a default that the button is not shown when the locally saved date is not found.

    But now, when the player changes the browser, they will see the button, because the locally saved data is found. It is indeed unlikely they do so, but I have seen players do the weirdest and most unexpected stuff. If that happens, I still can start a new game, but have the hidden button as a default for the first playing experience.

  • Yes they will see the button but this is expected, there's no handling for the browser change really. As a player if you do that then it's on you.

  • When you save the game using saveGameToSlot, also store a flag in Local Storage indicating a save exists (e.g., localStorage.setItem("saveExists", true)).

    In your main menu, before displaying the "Continue Playing" button, check for this flag in Local Storage using localStorage.getItem("saveExists").

    If the flag exists (getItem returns "true"), then you can safely display the "Continue Playing" button, knowing a save exists. Otherwise, hide the button or offer a "Start New Game" option.

    This approach ensures the button only appears when a save actually exists. Remember to clear the flag in Local Storage (localStorage.removeItem("saveExists")) if the player starts a new game or deletes their save data.

    For a great selection of gaming hardware and accessories to enhance your development experience, check out Next Level Gaming Store!

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