And another question from me, do you understand what Nestharus wrote in his tutorial (
http://www.hiveworkshop.com/forums/jass-ai-scripts-tutorials-280/saving-loading-192851/)?
The intro is quite important. Once he starts about BigInt and such, you can stop reading
It explains the basics of how a code is formed (well, the very basics, really).
A working save/load code would be to set all heroes and items in arrayed variables, like:
-
Set hero[1] = Lich
-
Set hero[2] = Dreadlord
-
Set item[1] = Claws of Attack +15
-
Set item[2] = Mask of Death
-
Set item[3] = Wirt's Leg
-
Set heroAmount = 2
-
Set itemAmount = 3
And then checking "is the hero of the triggering player hero[X]"? (With a loop), such as:
-
Actions
-
Set saveString = <Empty String>
-
For each (Integer A) from 1 to heroAmount, do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Unit-type of playerHero[(Player number of (Triggering player))]) Equal to hero[(Integer A)]
-
Then - Actions
-
Set saveString = (saveString + (String((Integer A))))
-
Else - Actions
I mean, that
works.
If you do the same for items (say "no item" is 0, the rest is the array), then my hero's save-code could look like:
2100320
To break it down:
2: Hero - Dreadlord
1: Item - Claws
0 - Item - no item (empty slot)
0 - Item - no item (empty slot)
3 - Item - Wirt's Leg
2 - Item - Mask
0 - Item - no item (empty slot)
This is the absolute basis, I don't think it can get any easier than this.
Extremely easy to crack and change to what you want, but it works!
Loading would be the other way around: the first number is 2, so create "hero[2]" for player.
Give items in the same order (you can use dummy items for the zero's so the items are assigned in the correct slot as well).
The hard part is when you start encrypting/decrypting and shortening the code.
Saving isn't hard, but remember: you need to load it as well.
If I add experience (hero - experience - items), then my code could be: 18001 (Lich (1), 800 XP, claws).
It could also be: 1100001 (Lich (1), 1000 XP, Claws).
Do you see the problem that arises? You HAVE to let your system know that the first code only uses 3 characters for the XP and the last uses 4 characters.
Otherwise it would either give 8001 XP for the first code and no item, or 100 XP for the second code and empty slot - claws as items.
You can do this by setting a maximum value, say 5400XP. That is 4 characters.
Now the first code becomes: 108001 (Lich (1), 0800 XP, Claws).
However, this stretches your code to the maximum (literally, as all codes will have the maximum possible length, as even the lowest values will be increased so they're longer).
2 options:
1) Deal with it Let players type the full code the entire time (the only advantage is that the code will always have the same ordening).
2) Do like Nestharus did and do some complicated stuff to make it dynamic (I don't recommend the QueueQueue for you yet though, it's a complex data structure, really useful for this).
And this is where my story ends... and I didn't even get to actually encrypting the code yet (with the magics of math).