Using Full State Save/Load

Get help using Construct 2

Post » Tue Sep 24, 2013 2:49 am

Has anyone used the full state save/load feature successfully?

I can't seem to figure out two things.

1. Check whether a saved game exists. I read that you can use web storage to check, but it does not appear to work.

2. Clear saved games.

Do you just have to use web storage instead of the full state load/save?
B
26
S
8
G
2
Posts: 33
Reputation: 3,645

Post » Tue Sep 24, 2013 8:10 am

I'm not sure whether or not the savegame system can be accessed by WebStorage. I know that it uses the system, but I don't think it does so in the same way as the WS object. I don't think you can access the keys, for example.

Checking whether a save game exists is a matter of running the Load game action, which will either load the save game if it's found, or report back that it can't be found. In the latter case, you'd use the On load failed action to tell the player that the game can't be loaded.

Clearing savegames seems to be a feature that's missing, frankly. I can only suggest that, to create the impression of deleting a savegame, you clear all global variables and WS data, then save over the current savegame at the game's main menu. Either that, or perpetually create new savegame names, and only ever make the last one accessible - although that'd get pretty messy over time.

Personally, I don't use the savegame system, at least not for my current project. I much prefer to use WebStorage where I can focus on saving exactly the data that I want.
B
57
S
15
G
11
Posts: 912
Reputation: 12,626

Post » Tue Sep 24, 2013 10:55 am

The best approach is to store metadata in WebStorage about which save slots are in use. Then to clear savegames just clear the WebStorage keys you've been keeping about which slots are in use.
Scirra Founder
B
399
S
236
G
89
Posts: 24,521
Reputation: 195,375

Post » Tue Sep 24, 2013 5:54 pm

Thanks for the replies. I will give it a try and report back.
B
26
S
8
G
2
Posts: 33
Reputation: 3,645

Post » Tue Sep 24, 2013 7:30 pm

I got it working using Ashley's suggested method.

I offer 2 save slots in my game. On main menu, there are 4 buttons. 2 to clear each of the save slots. And 1 button for each save slot. Each save slot button has 2 frames. "New Game" and "Continue".

On the start of the main menu layout, I check web storage to see if the key "save1" and "save2" exist. If it does, the corresponding slot button is changed to "Continue". I have 2 variables, save1Exists and save2Exists. If the web storage key exists the corresponding variable is set to 1.

When either of the save slot buttons are clicked, the system checks if the corresponding saveExists variable is set to 1. If it is, I have another variable called "savedGame" that is set to the value of the web storage key of "save1" or "save2" depending on which button was clicked. Then I load the game from save slot savedGame. The game is only saved at the main layout.

If the saveExists variable is not set to 1, I set the web storage key "save1" or "save2" to "myGameName(1 or 2 depending on save slot)". I then set the savedGame variable to this web storage value. Then I load the main layout.

When the main layout loads, the game is saved to save slot savedGame. This main layout is more of a hub layout for the player to move between doing missions, purchasing upgrades and such.

There may be a better way to do this but, this worked for me.
B
26
S
8
G
2
Posts: 33
Reputation: 3,645


Return to How do I....?

Who is online

Users browsing this forum: Christmas and 62 guests