• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

question about save/load codes, part 2

Status
Not open for further replies.
Level 12
Joined
Mar 21, 2008
Messages
358
sequel to this thread, but only indirectly related

i am using triggerhappy's codegen system and i'm looking for ways to shorten the save code it produces

my issue is that i have 3 inventories to be saved in addition to the charges of each of those items, which makes the save code pretty chunky

additionally, in codegen you have to specifically order the things you want to save, so it seems i can't avoid saving unnecessary information like the following:
- empty inventory slots
- item charges for an empty inventory slot
- item charges on an item that doesn't use charges
is there any way to avoid saving "useless" stuff???? or am i fricked

tl;dr i have two questions:
1. how do i save 3 inventories + item charges of each item while not bloating the length of the save code
2. how can i avoid saving unnecessary stuff e.g. empty inventory slots

too long didn't read the tl;dr: im dum help me
 
Level 12
Joined
Mar 21, 2008
Messages
358
You answered this yourself:
oh damn u got me

also, judging by the latest posts on codeless save/load, it seems reforged has fucked it completely so i either have to wait for a wc3 patch that makes it usable again, or i can continue my autistic endeavor into save code shortening in the meantime because i have nothing better to do
 

Uncle

Warcraft Moderator
Level 67
Joined
Aug 10, 2018
Messages
6,906
You can avoid saving useless stuff by filtering it out.

Saving a Heros inventory slots:
For each integerA from 1 to 6
If Item carried by hero in Slot IntegerA not equal to No Item
Save the Item

And while on the subject of save and load systems, I was messing around with saving/loading files and I'm still a bit confused as to why there are so many limitations in these systems like how much you can save and the limited code length.

As far as I can tell you can save as many files as you want and load as many as you want. I'm not sure how the syncing stuff goes but I imagine that's the difficult part.

Here's some snippets from a Save system I created using Lua:
Lua:
function SaveItemToFile(p, f)
    local savestring = ""
    print("Save To File", f)
    --Save File
    savestring = SaveStringTable[f]
    PreloadGenClear()
    PreloadGenStart()
    BlzSetAbilityTooltip(FourCC(SaveAbil), savestring, 0)
    Preload("\")\ncall BlzSetAbilityTooltip('A000',\""..savestring.."\",0)\nreturn//")
    PreloadGenEnd("Test\\"..SaveItemFile[f]..".txt")
end

function LoadItemFromFile(f)
    local loadstring = ""
    print("Load File", f)
    --Load File
    Preloader("Test\\"..SaveItemFile[f]..".txt")
    loadstring = BlzGetAbilityTooltip(FourCC(SaveAbil), 0)
    print("load string:", loadstring)
    --Base, Level, Rarity, Ethereal, Sockets
    LoadItemInfo(loadstring)
end
I wanted to save/load Diablo 2-style Items (Items with randomly generated stats) which would require saving a ridiculous number of variables. Saving 50+ items in your stash, each item with 10+ Variables assigned to it. It gets crazy.

Anyway, I managed to get it working in singleplayer. It saves multiple files in your CustomMapData folder and each file has code like this:
callBlzSetAbilityTooltip('A000',"a1a1a5a1a0ba1a1a5a1a0ba1a1a1a1a0ba1a1a2a1a0ba1a1a3a1a0ba1a1a3a1a0ba1a1a3a1a0ba1a1a5a1a0ba1a1a3a1a0ba1a1a5a1a0baz",0)

Then I use string.find to decipher the code when Loading it. I forget what the variable i represents here but it had to do with finding the correct letter:
Lua:
i = string.find(s, "a", i+1) --find the next letter a
I forget the details exactly but basically after each "a" is an Integer that represents the value of a stat. The letter "b" is used to separate the items. The letter "z" at the end is used to mark the end of the string.

Now the question is, how the hell do I convert something like this into a code that players can't read/edit so easily? And how do I sync this information with other players so it can be used in multiplayer? On top of that, every save system I've seen only uses 1 save file, which makes me wonder if what i'm doing is even possible on bnet.
 
Last edited:
Level 12
Joined
Mar 21, 2008
Messages
358
You can avoid saving useless stuff by filtering it out.

Saving a Heros inventory slots:
For each integerA from 1 to 6
If Item carried by hero in Slot IntegerA not equal to No Item
Save the Item
well my issue was trying to figure out what the corresponding part in the load trigger would look like

since you are saving any number of items from 0-6, you would somehow need to convey to the load trigger that you have x amount of items. otherwise, how would you know how many items to load?

i came up with a kinda shit solution where i just saved the number of items the hero was holding; then in the load trigger, you load that value prior to the item load, then you just do a for loop from 1 to (number of items) then create the items

anyway this doesn't shorten the code terribly much, but it avoids saving empty inventory slots and other useless poop

there's probably a better way of doing this but whomst cares
 
Status
Not open for further replies.
Top