How to make and name save game slots

3

Stats

7,720 visits, 11,785 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 11 Jun, 2012. Last updated 19 Feb, 2019

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.

SECTION 2

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.

  • 4 Comments

  • Order by
Want to leave a comment? Login or Register an account!