Know another language? Translate this tutorial!

How to make and name save game slots

Favourite 90 favourites
Tutorial written by ShyrionOriginally published on 11th, June 2012 - 16 revisions

In this tutorial we'll see a method to create a "Load Game" layout and an in-game screen for saving/loading with more than one slot; using Web-storage and an array.

Probably there's a better way to do it, but this way works perfectly.

Lets start:

First the objects we'll need:

1. At least one button for saving.

2. At least one button for loading.

3. At least one button for exit "save game" screen.

4. At least one text box so the player can name his saved games.

5. An array, set as global object, to store the names of the slots and local variables.

6. An image to "hide" the scenario (I use one of 1024x768 painted black, but anyone will do the trick).

7. Two parallax 0,0 layers.

I use a "global" event sheet where I put the code that I use in every scenario, but you can do this as you wish.

We'll need that when a key is pressed, the screen changes into another with all objects. To exemplify this, I'll use an image:
"P" refers to player and "E" to enemies.

What we're doing here is stop objects movement to avoid player death or so while saving game.

Next, we create the image in layer "HUD2" (A "parallax 0,0" layer wich we use to do de "hide" trick). The "set opacity to 80" action was there to verify that all was working correctly; it's not necessary.

Now we create the objects at layer HUD and the positions we desire, and set "exit button" to enabled. I think the picture explains by itself.

Now another one:
What we're doing here is using a global variable as a switch "to turn off" save screen, and destroying all objects.

The screen as is set above, appears as this image shows:
Don't forget to set a default text in the textbox, in case the array position is blank (default at start)
Use global variables as "switches", exactly as the tutorial for creating leaderboards teaches us, AND DON'T FORGET TO SAVE THEM, at least, the ones for Load Buttons:
And set the conditions for buttons to be activated and what text to show:
Commands in picture above are for preventing to try to load a blank save slot (default and blank text).

Next, we define the actions for saving the game:

As we see in this picture, we use for "button 1" and "Textbox 1" the position (0,1) on ArraySave (and so on); there is where we store the name of the saved game. It's necessary to use one array exclusively for this purpose. When we create the "load game" screen for the start menu of the game we'll see why.

Note that when saving, following the name of the file in disk is this string "& ArraySave.At(0,1)", this is for identify wich "save slot" is, appending the name of the saved game to each saved file.

Once the "save name" is set into the array, we proceed to copy all local variables we use into the array (I use another for this, my "general array" but you can use different positions for each save slot in the same array).

The next thing to do, and a very important one, is to put into the array the coordinates of your player, save the arrays and turn on the switch. Here you can display text showing the player that the game is saved if you want. You only need a text object and the command "set text" for this, instead of turning on the switch.

Note that if you don't press "save", any text you write in the textbox will dissapear, so exiting and reentering the save screen is a sort of "undo changes".

Now, for loading:

First we load the array, and recover from it the local variables we put before. Next we load the global variables from webstorage.

Don't forget to save in which scenario is the player. I use a global variable and on start I set its number to the scenario's. The picture above lacks the command we'll need for this: System--->Go to layout...

Once the game goes to the "saved" layout, we set player's position, extracted from the array, and turn on the switch to restart play.


Creating a layout for loading at start:

Again, a picture for exemplifying:

The important thing here is setting the size of the arrays and load ONLY the Save Array, where we stored the names of the save slots.

In this screen I've put a clear button, that works as seen here:
Composing this layout as we did before with the "save/load" in-game screen, but without save button, we can load it same way we did before. The screen, in my case, is as follows:
At start of this layout I set textbox to readonly, for this is a loader layout, and at my global event sheet I return them to read-write.

Unlock your full gamedev potential

Upgrade to the Personal Edition of Construct 2, it has way more features and won't holding back from making money and using your full creativity like the free edition does. It's a one off payment and all Construct 2 editor updates are free for life!

View deals

Plus, it's got a lot of additional features that will help you save time and make more impressive games!

Congratulations on finishing this tutorial!

Did you learn a lot from it? Share it now with your friends!


AJTilley 5,086 rep

Thanks for the tutorial this is an interesting way of doing save games.

In the past the way I have done multiple save game slots, is simply with webstorage with different webstorage values with an id number for each save game slot, then pressing load only loads specific variables from the webstorage rather than all of them e.g. a players health in save slot 1 would be health1 and in save slot 2 health2. Then when they press load the button takes the appropriate values for that slot, eliminating the need for an array.

I personally find arrays a bit of a pain and tricky so try to avoid them where possible. Not sure which version would be better or easier to use.

Monday, June 11, 2012 at 3:14:54 PM
Shyrion 4,347 rep

Yes, the version you comment could be of use too!

Yesterday was thinking how to do this and started making it this way. The array allows to "name" the save slots, and that is the reason why I use it.

I'm working now on the "engine" to improve it to his "perfect state", so this tutorial has been a bit premature.

Monday, June 11, 2012 at 3:25:40 PM
Shyrion 4,347 rep

Now it works fine.

Wednesday, June 13, 2012 at 1:49:46 PM
MelVin 9,094 rep

Thanks for sharing the Tut. If it's not to much to ask could you post a capx for this. I've been stuck for a few days now trying to get this to work for me. Thanks.

Tuesday, July 31, 2012 at 6:03:48 AM
turtlesaur 2,929 rep

I wish you uploaded a capx or something, I got lost when you starting using button toggles, as I used sprites for mine. Also referencing other tutorials is unfortunate, I have no idea which one you are referring to and now must go dig.

Friday, November 30, 2012 at 1:34:12 AM
Shyrion 4,347 rep

Ok. I will do so this week.

Sunday, December 02, 2012 at 7:52:09 PM
LaurenceBedford 11.7k rep
Ok. I will do so this week.
quoted from Shyrion

Please may you upload the capx?

Monday, January 22, 2018 at 7:20:50 AM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.