Creating Save Slots using Playmaker

Examples of using Easy Save 2 Playmaker actions to save and load.
Post Reply
User avatar
Joel
Moodkie Staff
Posts: 4812
Joined: Wed Nov 07, 2012 10:32 pm

Creating Save Slots using Playmaker

Post by Joel »

Creating Save Slots using Playmaker

In this tutorial, we will create a basic GUI which will contain a series of save slots, allowing up to 4 separate saved games. Each saved game will store a level number; when the save slot is clicked, that level will be loaded.

Creating a Save Slot Button

Our save slots will be represented by 4 buttons; one for each save slot. We will create a new scene which will contain these buttons, though it would also be possible to create them in an existing scene.
  1. Create a new scene and add a new GameObject to it. This will be our button.
  2. Add an FSM to this GameObject and name it something appropriate. We will name our first state 'Idle'.
  3. In the Action Browser, add a 'GUI Button' Action to the first state and set it to a suitable size and position.
  4. Right-click the state, select 'Add Transition' and add a 'MOUSE DOWN' transition.
  5. In our 'GUI Button' state, set 'Send Event' to 'FINISHED'. Now when this button is pressed, it will fire an event.
  6. In the 'Text' field, type 'Save Slot 1', or something similar. This will be the label on our button.
Loading our Level
  1. Go to the 'Variables' tab and add a variable named 'LevelNumber' with a Type of 'Int', and set it's value to the number of your first level (we've set ours to '1').
  2. Also under the 'Variables' tab, click 'Global Variables' and add a global variable called 'SaveSlot' of type 'String'. This will tell us where to save data for the currently selected slot.
  3. Now go to the 'Events' tab and add two new events: 'EXISTS' and 'DOESNOTEXIST'. Note that you will have to write the name of the event into the 'Add Event' text field, and then press Return to add the Event.
  4. Add a new state to the FSM called 'Set Save Slot', and add a 'FINISHED' transition to it.
  5. Add a 'Set String Value' action to our 'Set Save Slot' state, set the 'String Variable' field to the 'SaveSlot' global variable and set the 'String Value' field to the tag for this save slot (in this case, 'slot1').
  6. Add a new state to the FSM, which we will call 'Exists'.
  7. Right-Click the first 'Idle' state and set the 'Transition Target' to our 'Exists' state. When the button is pressed, this state will be activated.
  8. Open the Action Browser and add an 'Exists' Action (found in the 'Easy Save 2' section) to the 'Exists' state.
  9. In the 'Exists' state, set the 'If Exists' and 'If Does Not Exist' fields to the 'EXISTS' and 'DOESNOTEXIST' states we made earlier.
  10. Set the 'Unique Tag' to our 'SaveSlot' global variable. This is where we save our level number for this save slot.
  11. Add the two transitions to our 'Exists' state: 'EXISTS' and 'DOESNOTEXIST'.
  12. Create a new 'Load' state and link it to the 'EXISTS' transition of the 'Exists' state.
  13. Add a 'Load Int' Action to this State, set the 'Load Value' field to our 'LevelNumber' variable, and the Unique Tag field to our 'SaveSlot' global variable.
  14. Add a 'FINISHED' transition to this.
  15. Create a new 'LoadLevel' state and link it to the 'DOESNOTEXIST' transition of the 'Exists' state, and the 'FINISHED' transition of the 'Load' state.
  16. Add a 'Load Level Num' Action to this State, set the 'Level Index' field to our 'LevelNumber' variable, and untick 'Dont Destroy On Load'.
Repeat 'Creating a Save Slot Button' and 'Loading our Level' for each save slot, but instead using 'levelnumber2', 'levelnumber3', ect, as your Unique Tag. You should be able to save time by simply duplicating the GameObject containing the FSM. You will also want to change the size and position of each button so that they don't overlap.

Your FSM should look something like these:



Saving our Level Number

The easiest way to do this is to save the level number when we enter the level.
  1. Create a new GameObject in your scene and add an FSM to it.
  2. Name the first state 'Save', open the Action Browser and add the 'Save Int' state found under the 'Easy Save 2' section to it.
  3. In the 'Save Int' action, set the 'Save Value' to your level number, or a variable containing your level number.
  4. Set the 'Unique Tag' to our 'SaveSlot' global variable that we made earlier.
  5. When the scene starts, it will save the level number to the correct save slot. This tutorial is complete!
Note: To load the level, you must add it to the 'Scenes in Build' list in 'Files > Build Settings'. You can also find the Level Number here.
It should also be noted that you need to add the 'Save Slot' scene to 'Scenes in Build' for this to work.

Your FSM for the level should look like this:


Find below the Scenes for this example. You may need to go to 'Scenes in Build' list in 'Files > Build Settings' and add the Level 1, Level 2 and Level 3 scenes to the scene list.
ranajitdas33
Posts: 1
Joined: Mon Sep 08, 2014 8:14 am

Re: Creating Save Slots using Playmaker

Post by ranajitdas33 »

Thank you for the tutorial but
I did not found Save Int and Exists action in playmaker action browser.
Can you please help
User avatar
Joel
Moodkie Staff
Posts: 4812
Joined: Wed Nov 07, 2012 10:32 pm

Re: Creating Save Slots using Playmaker

Post by Joel »

Hi there,

You need to enable the Playmaker action by going to Assets/Easy Save 2 and clicking Enable or Update Playmaker Action. Then the action will appear under the Easy Save 2 section of the Playmaker action browser.

All the best,
Joel
codeman
Posts: 1
Joined: Wed Oct 21, 2015 7:12 pm

Re: Creating Save Slots using Playmaker

Post by codeman »

Hi Joel- I've got your example to work: I set up several scenes with the "Save Int" action, using increasing set values that save to my Global/SaveSlot variable. Returning to the home screen and pressing the "Load Level" button skips to the most currently completed scene. Woo!

Any ideas how I would set that global SaveSlot number to correspond to unlocking new stages in a level select scenario?
User avatar
Joel
Moodkie Staff
Posts: 4812
Joined: Wed Nov 07, 2012 10:32 pm

Re: Creating Save Slots using Playmaker

Post by Joel »

Hi there,

Generally if your levels are unlocked sequentially, you should be able to use the LevelNumber variable to determine the highest unlocked level number and disable all level numbers higher than this in your GUI.

If your levels aren't unlocked sequentially, because Playmaker doesn't support arrays, you will need to use ArrayMaker and it's Easy Save actions. As these actions aren't maintained by us, you'll be best off asking for advice on this on the Playmaker forums.

All the best,
Joel
Post Reply