Tutorial Creating a Save and Load System

Reaction score
341
Creating a Save and Load System
TriggerHappy187

Table of contents
  1. Initializtion Trigger
  2. The Save Trigger
  3. The Load Trigger

Introduction:

Alot of people have been asking around for save and load systems. Now here will be a simple tutorial that will teach you to make a simple save ( and load ) system. It will consist of three parts , The initialization trigger , The save trigger , and the load Trigger. This tutorial is meant for intermediate GUI users , although some beginners could figure it out.
 
Reaction score
341
Initialization Trigger :

This is the first part of our tutorial , Setting our values. What were going to do here is Store all the things we want to save , then give each thing a unique string. So lets start with heroes, Create a new variable with these properties :

  • Name : Whatever
  • Type : Unit Type
  • Array Box Checked

Once that variable is created, make a new trigger with the event as Map Initialization then set the variable , storing heroes that you want to save , For example :

Code:
Save Init
    Events
        Map initialization
    Conditions
    Actions
        Set HeroTypes[1] = Paladin
        Set HeroTypes[2] = Far Seer
        Set HeroTypes[3] = Lich

Now that we have the heroes stored that we want to be able to save , we must give them unique strings. For example , Say you wanted the Paladins Save String to be "A4" , so when a player typed -save and had the paladin , part of their code would have A4 because it's storing the paladin. So set it up like this :

Code:
Save Init
    Events
        Map initialization
    Conditions
    Actions
        Set HeroTypes[1] = Paladin
        Set HeroString[1] = Sa
        Set HeroTypes[2] = Far Seer
        Set HeroString[2] = Pl
        Set HeroTypes[3] = Lich
        Set HeroString[3] = Gt

Though , you can pick whatever strings you want but make sure their all the same length. Now create a new variable with the following properties :

  • Name : Whatever
  • Type : Integer

Then set it in the init trigger to how many heroes are saved.

Code:
Save Init
    Events
        Map initialization
    Conditions
    Actions
        Set HeroTypes[1] = Paladin
        Set HeroString[1] = Sa
        Set HeroTypes[2] = Far Seer
        Set HeroString[2] = Pl
        Set HeroTypes[3] = Lich
        Set HeroString[3] = Gt
        -------- ------------- --------
        Set Number_of_Heroes = 3

It was set to 3 since i have 3 stored heroes. Now you can do this for the rest of the things you want to save , like items.


 
Reaction score
341
Save Trigger :

The save triggers is what gathers certain information and stores it into a string , then displays it to the player. This string can be decoded and restore the stored values. First , setup your trigger's events like this.

Code:
Save
    Events
        Player - Player 1 (Red) types a chat message containing -save as An exact match
        Player - Player 2 (Blue) types a chat message containing -save as An exact match
        Player - Player 3 (Teal) types a chat message containing -save as An exact match
        Player - Player 4 (Purple) types a chat message containing -save as An exact match
    Conditions
    Actions

This is pretty self explanitory. Now in this save demo ill show you how to save a hero , but after this you should understand how to save anything you want. Ok were going to need to find if the Triggering Player has a hero , Do this by using a Unit Group

Code:
Unit Group - Pick every unit in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True)) and do (Actions)
    Loop - Actions

This will find the hero owned by the person who typed -save. Next is to see if the hero is in the array and if it is , display the string. But first we will need a new variable :)

  • Name : Final_Code
  • Type : String

Once you created that variable were going to have to loop through the hero array to see if the picked hero matches any one of them. Do so like this :

Code:
For each (Integer A) from 1 to Number_of_Heroes, do (Actions)
    Loop - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                 HeroTypes[(Integer A)] Equal to (Unit-type of (Picked unit))
            Then - Actions
            Else - Actions

That means it will loop through all the heroes and IF the picked unit's type is equal to any of them , it will the the Then - Actions. Now we get to setup the code to be displayed to the player. So what we do is Get the string corresponding to the same array that the hero was found. Like so :

Code:
Set Final_Code = (Final_Code + HeroString[(Integer A)])

That will set the code to the heroes string that was stored in the init trigger. Congrats you just made a save trigger , but we still have some touching up to do on it. First you need to set Final_Code = <Empy String> At the beggining of the code. And we need to display the code to the player right? so the code should look something like :

Code:
Save
    Events
        Player - Player 1 (Red) types a chat message containing -save as An exact match
        Player - Player 2 (Blue) types a chat message containing -save as An exact match
        Player - Player 3 (Teal) types a chat message containing -save as An exact match
        Player - Player 4 (Purple) types a chat message containing -save as An exact match
    Conditions
    Actions
        Set Final_Code = <Empty String>
        Unit Group - Pick every unit in (Units owned by (Triggering player) matching (((Matching unit) is A Hero) Equal to True)) and do (Actions)
            Loop - Actions
                For each (Integer A) from 1 to Number_of_Heroes, do (Actions)
                    Loop - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                 HeroTypes[(Integer A)] Equal to (Unit-type of (Picked unit))
                            Then - Actions
                                Set Final_Code = (Final_Code + HeroString[(Integer A)])
                            Else - Actions
        Game - Display to (Player group((Triggering player))) for 60.00 seconds the text: Final_Code

 
Reaction score
341
Load Trigger

Las but not least the load trigger. This part should be pretty simple , though its the hardest ( IMO ) Out of all the parts. All were doing is checking for certain strings. Set it up like normal :

Code:
Load
    Events
        Player - Player 1 (Red) types a chat message containing -load  as A substring
        Player - Player 2 (Blue) types a chat message containing -load  as A substring
        Player - Player 3 (Teal) types a chat message containing -load  as A substring
        Player - Player 4 (Purple) types a chat message containing -load  as A substring
    Conditions
        (Substring((Entered chat string), 1, 6)) Equal to -load 
    Actions

Make sure there is a space after -load. To make things simpler we will set our final code var to only the entered code , instead of the entire string. Do it like this :

Code:
Set Final_Code = (Substring((Entered chat string), 7, (Length of (Entered chat string))))

Now we will decode :) , First we will start with heroes since that's all we saved in this tutorial. What were going to do is loop through the entire code checking if certain parts are a stored string from the array , then restore the value from the variable. So make another loop like this :

Code:
For each (Integer A) from 1 to (Length of Final_Code), do (Actions)
    Loop - Actions

Then make an if then else , and as the condition do this :

Code:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    If - Conditions
        (Substring(Final_Code, (Integer A), ((Integer A) + 1))) Equal to HeroString[(Integer A)]
    Then - Actions
    Else - Actions

Make sure you change the +1 to equal the length of the stored strings in the map init - 1. So say your string was 5 letters long , you would do 5-1 = 4 so , Integer A + 4 would be what you used.

Now we can restore the value , This loop is checking for heroes so we will restore the hero by adding 1 more line :)

Code:
Unit - Create 1 HeroTypes[(Integer A)] for (Triggering player) at (Center of (Playable map area)) facing Default building facing degrees

And your done! You have created a simple save and load system. Here is the final trigger :

Code:
Load
    Events
        Player - Player 1 (Red) types a chat message containing -load  as A substring
        Player - Player 2 (Blue) types a chat message containing -load  as A substring
        Player - Player 3 (Teal) types a chat message containing -load  as A substring
        Player - Player 4 (Purple) types a chat message containing -load  as A substring
    Conditions
        (Substring((Entered chat string), 1, 6)) Equal to -load 
    Actions
        Set Final_Code = (Substring((Entered chat string), 7, (Length of (Entered chat string))))
        For each (Integer A) from 1 to Number_of_Heroes, do (Actions)
            Loop - Actions
                Game - Display to (All players) the text: (Substring((Entered chat string), (Integer A), ((Integer A) + 1)))
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Substring(Final_Code, (Integer A), ((Integer A) + 1))) Equal to HeroString[(Integer A)]
                    Then - Actions
                        Unit - Create 1 HeroTypes[(Integer A)] for (Triggering player) at (Center of (Playable map area)) facing Default building facing degrees
                    Else - Actions

 
Reaction score
341
Bump?

EDIT : Woops... thought i was more than 24 hrs ago. I did it before i went to sleep. Guess im a couple hours off.
 

hunterrravyn

TH.net Regular
Reaction score
19
Well you may consider adding more things to this like,

How to do ability saving, Item Saving,Level Saving

and possibly a bit of encryption... but i get lost on that bit :confused:

Otherwise it might help some people figure out how they work

:thup:Good Job
 
Reaction score
341
Well. This isn't a system. But a tutorial on 1 simple method on creating a save/load. The encryption is up to you.
 

Romek

Super Moderator
Reaction score
963
Well. This isn't a system. But a tutorial on 1 simple method on creating a save/load. The encryption is up to you.
That's a bit pointless if the user doesn't know how to encrypt.
And saving multiple things is needed too IMO.
It's much harder to save one thing than to save any amount over.
 
Reaction score
341
For the last time. This is not a system. This is supposed to teach you one method of saving things. I Used heroes as an example. Using the same method you could save pretty much anything.
 

Ithladir

Member
Reaction score
5
I just like to say thx for putting in such a example, breaking down the complex (for me that is) way's of save/load triggers.
This is a huge help for myself in the ways of that im not copying your tut to get results but learning the basics so i can learn to make my own version of the selution and get the parts i want.

So i hope this is a comfort that shows you that there are people enoying your ways of teaching people instead of giving the final awnsers. :D
 

CaptDeath

New Member
Reaction score
103
hey i can use this in my map [cause if your to lasy to pick your hero]
thx so much =rep if i can
-----------off topic-------
i still want that hero selection system that i cant believe you got rid of or you could tell me how so i can remake it cause that was cool
 
Reaction score
341
There are many ways to make save/load systems , this is just the most basic and easiest way , i think.

Thanks for the comments.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top