• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

I need VERY simple save/load

Status
Not open for further replies.
Level 3
Joined
Mar 15, 2010
Messages
37
So, Is here any save/load system that contains only something like 4 number code system and saves only 1 integer (point number) without to much trigger / variable things? :am:
 
Level 12
Joined
Apr 16, 2010
Messages
584
I don't think that such system exists, but the triggers should not be a problem, here's a great save/load systems, that are used in many maps and work perfectly.
[self="http://www.hiveworkshop.com/forums/spells-569/codegen-0-06-a-177395/?prev=search%3Dsave%2Fload%26d%3Dlist%26r%3D20"]Code Gen[/self]
[self="http://www.hiveworkshop.com/forums/spells-569/igen-140399/?prev=search%3Digen%26d%3Dlist%26r%3D20"]iGen[/self]
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Note that all those triggers you see aren't exactly so you can store other things (like units etc).
They're there to encode/decode the message.

If you just need to save a single integer, it still needs to encode that integer so not everyone can just type -80 and get 800 gold (just a simple example).
It's done through a repeated cycle which is also backwards compatible (so you can decode it as well).
This is what the largest part of the code does.


Well, that may not mean much to you, so let me put it very simple: you'll always need a rather long code.

But I've tried to simplify AceHeart's system for you only need a few variables.
(Sorry, but I also introduced a few variables, used for the colors... :/).
Should be obvious enough I guess.
 

Attachments

  • Save Test.w3x
    34 KB · Views: 52
Level 3
Joined
Mar 15, 2010
Messages
37
Thank you all ! now im studying that save system... well its a little hard, always I try to copy paste that code thing in trigger manager in that map name area and copy paste it to my map, my world edit only shutdown? well im trying to make that work but with only errors while saving and crashing editor is not actually fast learning :D
 
Level 12
Joined
Apr 16, 2010
Messages
584
Well if you're using iGen you need JNGP, it's a program that has more possibilities then normal WE and destroys WE limits.
If yo get crash or smth like that means that you copied something wrong, check if you copied variables, id included.
If you use the Save Test attached by ap0calypse, wait for his replay, haven't tested it.
 
Level 3
Joined
Mar 15, 2010
Messages
37
well, I have tried all of them, gonna try that JNGP. last time I have it it didnt work actually but still have to try. and yes, I have all the correct variables copied.
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
I just tried importing the save system I gave you (in an empty map) and it worked for me.
Since I do not know where you went wrong, I'll create a very small tutorial for you.
If it still fails after this, you could give me your map and I'll import it for you.

Getting started:
You do NOT need JNGP or any other program apart from the regular WE for this.
The most important thing you need first is to go to File -> Preferences and in the tab "General", enable "Automatically create unknown variables while pasting trigger data".
When that's done, something that isn't really important for now but might help in the future: in the "Test Map" tab (still in the same window), disable "Fixed Random Seed".

Importing:
First you need to copy/paste the header (go to the trigger editor, select the header (the thing above all categories, which is the title of the map) and copy the entire text on the right side of the screen.
For your simplicity, I'll add that header here to the post:
JASS:
function SaveLoad_Color takes string s returns string
    local integer i = StringLength(s)
    local string c
    local string r = ""

    loop
        set i = i - 1
        set c = SubString(s,i,i + 1)
        if c == "0" or c == "1" or c == "2" or c == "3" or c == "4" or c == "5" or c == "6" or c == "7" or c == "8" or c == "9" then
            set r = udg_ColorNumbers + c + "|r" + r
        elseif c == "a" or c == "b" or c == "c" or c == "d" or c == "e" or c == "f" or c == "g" or c == "h" or c == "i" or c == "j" or c == "k" or c == "l" or c == "m" or c == "n" or c == "o" or c == "p" or c == "q" or c == "r" or c == "s" or c == "t" or c == "u" or c == "v" or c == "w" or c == "x" or c == "y" or c == "z" then
            set r = udg_ColorLowercase + c + "|r" + r
        elseif c == "@" or c == "#" then
            set r = udg_ColorSymbols + c + "|r" + r
        elseif c == "-" then
            set r = "|c00cccccc-|r" + r
        else
            set r = udg_ColorUppercase + c + "|r"  + r
        endif
        exitwhen i <= 0
    endloop
    return r
endfunction

function SaveLoad_EncodeChar takes string n returns integer
    local integer i = 0
    local string s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    local string s2 = "abcdefghijklmnopqrstuvwxyz"
    local string s3 = "0123456789"

    loop
        if SubString(s1,i,i + 1) == n then
            return i
        endif
        if SubString(s2,i,i + 1) == n then
            return i
        endif
        set i = i + 1
        exitwhen i >= 26
    endloop
    set i = 0
    loop
        if SubString(s3,i,i + 1) == n then
            return i
        endif
        set i = i + 1
        exitwhen i >= 10
    endloop
    return 0
endfunction

function SaveLoad_EncodeVerify takes string buffer returns integer
    local integer i = 0
    local integer j = 0
    local string name = GetPlayerName(GetTriggerPlayer())
    loop
        set j = j + SaveLoad_EncodeChar(SubString(name,i,i + 1))
        set i = i + 1
        exitwhen i >= StringLength(name)
    endloop
    
    set i = 0
    loop
        set j = j + SaveLoad_EncodeChar(SubString(buffer,i,i + 1))
        set i = i + 1
        exitwhen i >= StringLength(buffer)
    endloop
    return j
endfunction

function SaveLoad_EncodeValues takes nothing returns string
    local integer i
    local integer j
    local integer k
    local integer l
    local integer m
    local integer CodeLength = StringLength(udg_SaveLoad_Alphabet)
    local integer array a
    local string buffer = ""
    local string c = ""
    local integer skip = 0
    local integer CONST = 1000000
    local string abc = "0123456789"

    set i = 0
    loop
        set i = i + 1
        exitwhen i > udg_SaveCount
        set buffer = buffer + I2S(udg_Save[i]) + "-"
    endloop
    set buffer = buffer + I2S(SaveLoad_EncodeVerify(buffer))
    if udg_Save[1] == 0 then
        set buffer = "-" + buffer
    endif

    set i = 0
    loop
        set a[i] = 0
        set i = i + 1
        exitwhen i >= 100
    endloop

    set m = 0
    set i = 0
    loop
        set j = 0
        loop
            set a[j] = a[j] * 11
            set j = j + 1
            exitwhen j > m
        endloop

        set l = 0
        set c = SubString(buffer,i,i + 1)
        loop
            exitwhen SubString(abc,l,l + 1) == c
            set l = l + 1
            exitwhen l > 9
        endloop
        set a[0] = a[0] + l

        set j = 0
        loop
            set k = a[j] / CONST
            set a[j] = a[j] - k * CONST
            set a[j + 1] = a[j + 1] + k
            set j = j + 1
            exitwhen j > m
        endloop
        if k > 0 then
            set m = m + 1
        endif
        set i = i + 1
        exitwhen i >= StringLength(buffer)
    endloop

    set buffer = ""
    loop
        exitwhen m < 0
        set j = m
        loop
            exitwhen j <= 0
            set k = a[j] / CodeLength
            set a[j - 1] = a[j - 1] + (a[j] - k * CodeLength) * CONST
            set a[j] = k
            set j = j - 1
        endloop
        set k = a[j] / CodeLength
        set i = a[j] - k * CodeLength
        set buffer = buffer + SubString(udg_SaveLoad_Alphabet,i,i + 1)
        set a[j] = k
        if a[m] == 0 then
            set m = m - 1
        endif
    endloop

    set i = StringLength(buffer)
    set skip = 0
    set c = ""
    loop
        set i = i - 1
        set c = c + SubString(buffer,i,i + 1)
        set skip = skip + 1
        if skip == 4 and i > 0 then
            set c = c + "-"
            set skip = 0
        endif
        exitwhen i <= 0
    endloop
    return c
endfunction

function SaveLoad_DecodeValues takes string s returns boolean
    local integer i
    local integer j
    local integer k
    local integer l
    local integer SaveCode = 0
    local integer m
    local integer array a
    local string buffer = ""
    local integer CodeLength = StringLength(udg_SaveLoad_Alphabet)
    local integer skip = -1
    local integer CONST = 1000000
    local string abc = "0123456789-"
    local string c

    set i = 0
    loop
        set a[i] = 0
        set i = i + 1
        exitwhen i >= 100
    endloop

    set m = 0

    set i = 0
    loop
        set j = 0
        loop
            set a[j] = a[j] * CodeLength
            set j = j + 1
            exitwhen j > m
        endloop

        set skip = skip + 1
        if skip == 4 then
            set skip = 0
            set i = i + 1
        endif

        set l = CodeLength
        set c = SubString(s,i,i + 1)
        loop
            set l = l - 1
            exitwhen l < 1
            exitwhen SubString(udg_SaveLoad_Alphabet,l,l + 1) == c
        endloop
        set a[0] = a[0] + l

        set j = 0
        loop
            set k = a[j] / CONST
            set a[j] = a[j] - k * CONST
            set a[j + 1] = a[j + 1] + k
            set j = j + 1
            exitwhen j > m
        endloop
        if k > 0 then
            set m = m + 1
        endif
        set i = i + 1
        exitwhen i >= StringLength(s)
    endloop

    loop
        exitwhen m < 0
        set j = m
        loop
            exitwhen j <= 0
            set k = a[j] / 11
            set a[j - 1] = a[j - 1] + (a[j] - k * 11) * CONST
            set a[j] = k
            set j = j - 1
        endloop
        set k = a[j] / 11
        set i = a[j] - k * 11
        set buffer = SubString(abc,i,i + 1) + buffer
        set a[j] = k
        if a[m] == 0 then
            set m = m - 1
        endif
    endloop

    set i = 0
    set j = 0
    loop
        loop
            exitwhen i >= StringLength(buffer)
            exitwhen i > 0 and SubString(buffer,i,i + 1) == "-" and SubString(buffer,i - 1,i) != "-"
            set i = i + 1
        endloop
        if i < StringLength(buffer) then
            set k = i
        endif
        set SaveCode = SaveCode + 1
        set udg_Save[SaveCode] = S2I(SubString(buffer,j,i))
        set j = i + 1
        set i = i + 1
        exitwhen i >= StringLength(buffer)
    endloop

    set j = SaveLoad_EncodeVerify(SubString(buffer,0,k))
    set udg_SaveCount = SaveCode - 1
    if j == udg_Save[SaveCode] then
        return true
    endif
    return false
endfunction

function SaveLoad_Decode takes string s returns boolean
    if SaveLoad_DecodeValues(s) then
        return true
    endif
    return false
endfunction

Now go to your own map, go to your map's header and paste the entire thing there (make sure it's completely pasted... world editor sometimes doesn't paste it completely).


When that's done, you need to copy the GUI triggers.
Go back to the save-map, right-click the category "Save Load ALL" and select "copy".
Go to your own map and paste this category somewhere.

The save/load system should work now.

Editing the system:
Since you probably don't want to save the gold but something else, go to the trigger "SaveLoad Save All" and edit the action "Set Save[1] = [YOUR INTEGER HERE]".
Now go to the trigger "SaveLoad Load All" and change the action "Player - Set (Triggering player) Current gold to Save[SaveCount]" to whatever you want.

You're free to change anything in the trigger "SaveLoad Initialization" (I believe I named that one wrong, sorry for that: drop the "hero"-part :D).


I hope this worked.
 
Level 3
Joined
Mar 15, 2010
Messages
37
Thank you so much ap0calypse ! it works fine as long as I have tried it with me and friend ! now I can continue doing my map ! :)
 
Status
Not open for further replies.
Top