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
964
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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top