Save/Load Code, Simple (GUI)

Discussion in 'Tutorial Repository' started by elmstfreddie, May 31, 2007.

  1. elmstfreddie

    elmstfreddie The Finglonger

    +203 / 0 / -0
    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!

    Knowledge of integer loops (if not read this)

    1. 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.
    2. Make a string variable called ItemTypesCoded with an array also
    3. Make a unit type variable, call it HeroTypes, ALSO with an array
    4. Make a string variable again, call this one HeroTypesCoded
    5. Repeat the what you want to save variable type and string variable until you have every type of what you plan to save.
    6. Finally make a string variable with an array, call it SaveParts
    7. 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)
    1. set ItemTypes[1] to your first item
    2. 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, ^$.
    3. set ItemTypes[2] to your second item
    4. set ItemTypesCoded[2] to the 2 character code for THAT item.
    5. Repeat for all your variables
    6. 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!
    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.
    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:
    • 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 :)

    • 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 =/
    • Like Like x 9
  2. worldofDeath

    worldofDeath New Member

    +47 / 0 / -0
    He em i have read your turtoral great job im going to get to work on that. But i belive some people may want a map to go along with it. Got any thing in there you can whip out? Also what is the load /save code trigger for just saving a hero level?
  3. elmstfreddie

    elmstfreddie The Finglonger

    +203 / 0 / -0
    You can either break up the digits and save each number, or create a two digit code for each number, for example
    HeroLevelCoded[1] = as
    HeroLevelCoded[2] = 8t
    HeroLevelCoded[50] = KL

    The index being the level. I was hoping you guys could assume that, but I guess I'll add that in.

    Okay, I'll try to whip up a map later today.
  4. zoll3

    zoll3 New Member

    +16 / 0 / -0
    Good job ! .. Well it explained me enough .. so i give it 5/5 , and to you i give .. REPUTATION XD
    • Like Like x 1
  5. Effane

    Effane Save/Load Code Tutorial

    +51 / 0 / -0
    Most people will want to see more code. Also alot of it is in generalities. As someone who has made a save/load they will want to know how its built, how to modify it and the specific things to change.

    Since your having loops to find things, why not use a loop to put your string together too. It will be more friendly for players to modify. If they dont know how to loop, they wont know how to use any of the trigger.

    Umm, show more code. It really is all about the trigger setup.

    Since there are a few approaches to Save/Load codes already try a different teaching approach. My PM list can tell you that mine obviously isnt reaching some people, nor aceharts. Maybe break it into two parts. One part teaching them how the parts and loops work. Then the second part is just code.

    I like the KISS thought though. We need an Ultra simple system for this. I can see some huge gaps in security though, but thats not really an issue for simple and fun "quicky" maps.

    Put a sample map in. They will want code they can touch. Make sure the map has methods to test and tinker like Random hero creations, items and such.

    Most of all, dont give up. I am starting to think we need about 100 save/load code tutorials so everyone will have a different veiw to read from.
  6. elmstfreddie

    elmstfreddie The Finglonger

    +203 / 0 / -0
    Yeah, I haven't gotten around to the sample map yet. I am definately going to make one.

    I guess at the end I'll have some sample snippits of the code from the map, which show what it should look like when they're making it.

    I've read it over a lot, and I still don't know what you're talking about with the KISS thing lol

    As for the loops thing, I actually have this old tutorial on understanding loops... Like, really old. Maybe I can link to it (once I read over it and make sure it's... good)

    Thanks for the comments :D

    I've been working on school stuff this weekend, and it's pretty late now. I might add the sample map and other stuff from your suggestions to it sometime next week.
  7. elmstfreddie

    elmstfreddie The Finglonger

    +203 / 0 / -0
    Okay.. Need to say two things:
    a) because of unexpected school delays, no test map yet :(
    b) I (as a joke), rated my own thread -.- however... it worked :eek: So... Ignore my rating LOL. (3 votes, all have been 5... One of those was mine)
  8. Prometheus

    Prometheus Everything is mutable; nothing is sacred Staff Member

    +592 / 0 / -0
    Then it doesn't matter.
    Anywho, nice code.
    +rep and a 5 star rate
  9. Dimaspy

    Dimaspy New Member

    +19 / 0 / -0
    <3 You!

    And get that sample done already, it's late July :p

    Edit: In the last example, this is written:
    If - Conditions
                    (Substring((Entered chat string), [B]5[/B], [B]6[/B])) ...
    Doesn't this 5 and 6 mean the 5th through 6th symbol in the entered chat string? In this case, wouldn't you get "d " (notice the space) as the item code thingy, out of "-load "? Or does the condition remove the "-load " part and takes 12345678 as the code?
    • Like Like x 1
  10. elmstfreddie

    elmstfreddie The Finglonger

    +203 / 0 / -0
    Uhm, apparently.
    That was just some random example, I think. I'll just fix that and pretend NOTHING EVER HAPPENED >_> lol
  11. Dimaspy

    Dimaspy New Member

    +19 / 0 / -0
    Hehehe, thanks :p
  12. SrH-Kush420

    SrH-Kush420 Guest

    +0 / 0 / -0
    I think you should put a final example like What the whole code should look like at the end not jus the loop.
  13. mr_fj

    mr_fj New Member

    +10 / 0 / -0
    Very nice indeed +rep
  14. eric92

    eric92 New Member

    +3 / 0 / -0
    That was nice man i give u rep elms
  15. The Helper

    The Helper Administrator Staff Member

    +1,213 / 2 / -1
    5 Star Bump

    5 Star Bump!
  16. Salaramon

    Salaramon New Member

    +0 / 0 / -0
    Soon 2010 and still no test map, do you know when the test map is about done?
  17. Synthetics

    Synthetics New Member

    +7 / 0 / -0
    Firstly i must say great tutorial, i've been looking at so many save/load tutorials and all there full of is billions of numbers and coding which i dont understand ive been looking at your and effanes tutorial and finally worked out how i can make a save load system

    the only part i dont understand is the text below

    if i understand the coding correctly, if player 1 was the triggering player the max would be 1 - 1 x12 which is should equal nothing or is 1 the minimal number with arrays so that 1-1=0x12=0 would equal 1 anyway?!?

    [((((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.

    im also a bit stuck with + (interger A))] is that for items only like how do we get the savedparts to equal the right array, like with the math that is written above how do i get saveparts[1] - saveparts[10]

    I dont know im probably being a bit thick, you have to dumb it down for me lol
  18. pirataliro

    pirataliro New Member

    +0 / 0 / -0
    Please help me is very important!

    Please help me is very important!

    It is very nice your tutorial I intend no more I'm Brazilian and I used all my resources to make this system please someone of you guys can do it on a map and send copy to see if I can work on my map! please! I need serious msm! please! If someone were to help me send me on my e-mail please help me!

    Please !! please! !!!
  19. GFreak45

    GFreak45 I didnt slap you, i high 5'd your face.

    +132 / 0 / -0

Share This Page