Save/Load Code, Simple (GUI)

Tutorial By elmstfreddie

GUI save loads can be a pain to make, but there is a simple way in which you can save everything.
This method however can make a long save/load, but still shorter than using raw data names of abilities, and is also very easy in GUI.

I am usually against planning maps on paper and such, but when making a save/load in GUI, it's best to either use excel or write on paper your method of madness. This is because in this save/load, you are able to scatter the data throughout the code.
So, get your paper ready!

Requirements:
Knowledge of integer loops (if not read this)

Pre-Making:Variables

• You will need quite a few variables, one for each thing you plan to save. All integers, reals, etc, can be represented with 1 variable. I'm sure you'll want to save items, so lets start with an item-type variable. Give it an array, and lets call it ItemTypes for simplicity.
• Make a string variable called ItemTypesCoded with an array also
• Make a unit type variable, call it HeroTypes, ALSO with an array
• Make a string variable again, call this one HeroTypesCoded
• Repeat the what you want to save variable type and string variable until you have every type of what you plan to save.
• Finally make a string variable with an array, call it SaveParts
• I'm assuming a hero is being saved, so you should have a Heroes variable with an array, array 1 representing player 1's hero, and the same for the rest of the player's heroes.


Now that you have all your variables made, you will now need to give all of them a value (this is the strenuous part). Make a trigger that runs on map init, and lets start by setting those variables! (I will show the example with the item variables)

• set ItemTypes[1] to your first item
• After that, set ItemTypesCoded[1] to equal the 2 character value you want to give to your first item (this is save/load is not case sensative!!!). It can be any set of 2 characters, i9, K2, ^$.
• set ItemTypes[2] to your second item
• set ItemTypesCoded[2] to the 2 character code for THAT item.
• Repeat for all your variables
• Finally, since you'll want to save the slot positions of items (even if there are spaces between them), you'll need an item called Slot Filler. Don't worry about it's effect; it will be removed from the unit's inventory soon. Now, set ItemTypes[any unused number] = Slot Filler

Note: Although the 2 character code can't be the same for 1 variable type (ie 2 Item-Types), it can be the same for two different variable types (ie 1 Item-Type and 1 Hero-Type)

Step 1: Creating the Save Trigger

This trigger (as you'd expect) should start with the event Player 1 types -save as an exact match. Now, make that event for every player. Player 2 types -save as an exact match, Player 3 types -save as an exact match, etc.
For an example, we will be saving just the items. Other things are saved the exact same way.
Okay, run an integer loop from 1-6. Make this one Integer A. Run an Integer B loop inside the Integer A loop, from 1-500 (or a higher number, it depends on how many items are in your game). In the B loop, add an if/then/else. The condition should be item type comparison, and should look like the following:
(Item-type of (Item carried by Heroes[(Player number of (Triggering player))] in slot (Integer A))) Equal to ItemTypes[(Integer B)]
That just checks that if the item in every slot is equal to one of the item type variables. This is used so that we know what string to use when assembling the save load.
Now, under then, we will set the string variable (SaveParts) to the coded version of the item type. The index on this variable will vary depending on how many parts your save/load has, but for example we will assume there is only 11 parts to the save/load. So, the index should be
[((((Player number of (Triggering player)) - 1) x 12) + (Integer A))]
What this does, is it makes the index 1-11 for player one, 12-23 for player 2, 24-35 for player 3, and so on. For player 1, 1-6 will be for the item slots. That's why we add integer A.
Now, what you set it to is ItemTypesCoded[(Integer B)]. Simple!
If you want this code extra secure, you can even save a different code. You could set the variable to ItemTypesCoded((Integer B) - 1)]. But if you did that, you must remember that, so that when saving you add 1 again, so it loads the correct item!
Under else, you have another if/then/else. In this, you check if the item in slot Integer A is equal to no item (this is an item comparison, not item-type comparison) then under the then for this, you set the string variable = ItemTypesCoded[number of Slot Filler item]. This is so that when we load the code, all items will be in the correct slot even if there are empty slots in between items.
Using this strategy, do a loop for everything you need to save. Levels, stats, gold, anything.

At the very end of this trigger, display the text to Player 1:
SaveParts[any number] + SaveParts[any number] + (dash) + SaveParts[any number] + SaveParts[any number] + (dash) + SaveParts[any number] + SaveParts[any number].
Repeat that, until you've displayed everything you saved. When I say any number, I'm just showing you can put, say, the code for slot 3 WHEREVER you want in the save/load. This makes it harder to crack it. Remember, it should be ((Player Number - 1) * 12) + Any Number).
Remember how I told you to either have some paper or open up Excel? Well, now is when you should write down where you put what in the save. If you put Hero Level after the second dash, then write that down!
Example:
This is what the item loop will look like when done correctly
For each (Integer A) from 1 to 6, do (Actions) Loop - Actions For each (Integer B) from 1 to 200, do (Actions) Loop - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Item-type of (Item carried by Heroes[(Player number of (Triggering player))] in slot (Integer A))) Equal to ItemTypes[(Integer B)] Then - Actions Set SaveParts[(((Player number of (Triggering player)) x 12) + ((Integer A) - 1))] = ItemTypesCoded[(Integer B)] Else - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Item carried by Heroes[(Player number of (Triggering player))] in slot (Integer A)) Equal to No item Then - Actions Set SaveParts[(((Player number of (Triggering player)) x 12) + ((Integer A) - 1))] = ItemTypesCoded[200] Else - Actions

Step 2: Creating the Load Trigger

Like the save trigger, this should start with a text event. This time, it should be Player X types -load as a substring. Because we are loading, there will be characters after load, which is why we need it to be a substring event. Now, someone might get good stuff by some horrible fluke by typing -load randomly in their message, so, you should have the condition (Substring(Entered Chat String(1,6))) = -load (space after the load).
Now, for loading we will use the same loop technique. This time though, we do the opposite! We run the loop, checking if sub strings are equal to the coded variables. For example(Substring((Entered chat string), 7, 8)) Equal to ItemTypesCoded[(Integer B)]
Under then, give the hero the item ItemTypes[(Integer B)]. Yet again, in else, there should be no actions.
HOWEVER, you cannot use a loop from 1-6 to do each slot, because I hope you scattered slots 1-6 randomly throughout the code! You'll need to load each substring separately (using a loop from 1-however many items you have), but in order from slots 1-6.
Now, after that, run another loop from 1-6, checking if the item in slot (Integer A) is equal to Slot Filler, if it is, then remove that item. If you don't do this, then people will see the Slot Filler item in their inventory!
Remember: The absolute first thing you should do is find the hero type of the loaded code, replace the current hero with the hero type, and set the heroes variable to the new unit.
Example:
If done correctly, one of the load loops should look like so:
For each (Integer A) from 1 to 200, do (Actions) Loop - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions (Substring((Entered chat string), 7, 8)) Equal to ItemTypesCoded[(Integer A)] Then - Actions Hero - Create ItemTypes[(Integer A)] and give it to Heroes[(Player number of (Triggering player))] Else - Actions
Believe it or not, you have just made a simple save/load in 3 triggers in GUI! Congratulations!

Pros and Cons of this save system:
Pros
• Easy to use, and all in simply 3 triggers
• Uses a random encryption, that really has no system to it
• Easy to scatter data throughout the code, making it hard to crack
• GUI friendly :)


Cons
• If you want to save it to a player's name, the code could get really long
• The more you wanna save, the longer it gets (and fast sometimes too)



Soon to come:
A test map, but dumb teachers at school are loading me with homework atm =/

Click here to comment on this tutorial.
 
 
Blizzard Entertainment, Inc.
Silkroad Online Forums
Team Griffonrawl Trains Muay Thai and MMA fighters in Ohio.
Apex Steel Pipe - Buys and sells Steel Pipe.