• 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.
  • Vote for the theme of Hive's HD Modeling Contest #7! Click here to vote! - Please only vote if you plan on participating❗️

Preload for save/load system - Need help (Lua)

Status
Not open for further replies.

Uncle

Warcraft Moderator
Level 71
Joined
Aug 10, 2018
Messages
7,608
Hi guys, I've decided to try something way over my head and I need some help. I'm trying to make a save and load system for my map. Here's the code i'm using:
Lua:
function ExampleSave()
    --Preload Start
    PreloadGenClear()
    PreloadGenStart()

    local teststring1 = "test string one"
    local lvlstring1 = "0"

    local teststring2 = "test string two"
    local lvlstring2 = "1"

    local teststring3 = "test string three"
    local lvlstring3 = "2"

    --Preload level 1
    BlzSetAbilityTooltip(FourCC('Amls'), teststring1, 0)
    Preload("\")\ncall BlzSetAbilityTooltip('Amls',\""..teststring1.."\","..lvlstring1..")\nreturn//")

    --Preload level 2
    BlzSetAbilityTooltip(FourCC('Amls'), teststring2, 1)
    Preload("\")\ncall BlzSetAbilityTooltip('Amls',\""..teststring2.."\","..lvlstring2..")\nreturn//")

    --Preload level 3
    BlzSetAbilityTooltip(FourCC('Amls'), teststring3, 2)
    Preload("\")\ncall BlzSetAbilityTooltip('Amls',\""..teststring3.."\","..lvlstring3..")\nreturn//")

    --Preload End
    PreloadGenEnd("Test\\Test.txt")
end
Lua:
function ExampleLoad()
    --Load Text
    Preloader("Test\\Test.txt")

    --Print the tooltip for level 1
    local teststring = BlzGetAbilityTooltip(FourCC('Amls'), 0)
    print("teststring 1:", teststring)

    --Print the tooltip for level 2
    teststring = BlzGetAbilityTooltip(FourCC('Amls'), 1)
    print("teststring 2:", teststring)

    --Print the tooltip for level 3
    teststring = BlzGetAbilityTooltip(FourCC('Amls'), 2)
    print("teststring 3:", teststring)
end
So i'm trying to use the tooltips for the Aerial Shackles ability ('Amls') to store my save code. This seems to work in the same game, that is if I save and load without making a new game it will load the tooltips properly. However, when I try to load the info from the PreloadFile in a new game it only works for the level 1 tooltip. The level 2 and 3 tooltips are lost in the process. The ability has 50 levels and I've filled in the tooltip for each level in the object editor.

I'm basing this system off of TriggerHappy's save & load system in which he uses the tooltips of multiple abilities to store information. I was hoping I could use one ability with multiple levels but it doesn't seem to work. Am I doing it wrong or is there an entirely better way of doing this?

Also, any tips, limitations, whatever that I should know about when making a save system? I know there will probably be sync issues but I figure I'll worry about that stuff after I get the basics down.

Edit:
What if I used multiple save files? Like this:
Lua:
--SaveAbil = 'A000'
function ExampleSave()
    --Preload Start
    local teststring1 = "test string one"
    local teststring2 = "test string two"
    local teststring3 = "test string three"
    local lvlstring = "0"
    local f = 1 --File #

    --Save File 1
    PreloadGenClear()
    PreloadGenStart()
    BlzSetAbilityTooltip(FourCC(SaveAbil), teststring1, 0)
    Preload("\")\ncall BlzSetAbilityTooltip('A000',\""..teststring1.."\","..lvlstring..")\nreturn//")
    PreloadGenEnd("Test\\"..SaveItemFile[f]..".txt")

    --Save File 2
    f = f + 1
    PreloadGenClear()
    PreloadGenStart()
    BlzSetAbilityTooltip(FourCC(SaveAbil), teststring2, 0)
    Preload("\")\ncall BlzSetAbilityTooltip('A000',\""..teststring2.."\","..lvlstring..")\nreturn//")
    PreloadGenEnd("Test\\"..SaveItemFile[f]..".txt")

    --Save File 3
    f = f + 1
    PreloadGenClear()
    PreloadGenStart()
    BlzSetAbilityTooltip(FourCC(SaveAbil), teststring3, 0)
    Preload("\")\ncall BlzSetAbilityTooltip('A000',\""..teststring3.."\","..lvlstring..")\nreturn//")
    PreloadGenEnd("Test\\"..SaveItemFile[f]..".txt")
end
Lua:
function ExampleLoad()
    --Preload Start
    local teststring = ""
    local f = 1 --File #

    --Load File 1
    Preloader("Test\\"..SaveItemFile[f]..".txt")
    teststring = BlzGetAbilityTooltip(FourCC(SaveAbil), 0)
    print("teststring 1:", teststring)

    --Load File 2
    f = f + 1
    Preloader("Test\\"..SaveItemFile[f]..".txt")
    teststring = BlzGetAbilityTooltip(FourCC(SaveAbil), 0)
    print("teststring 2:", teststring)

    --Load File 3
    f = f + 1
    Preloader("Test\\"..SaveItemFile[f]..".txt")
    teststring = BlzGetAbilityTooltip(FourCC(SaveAbil), 0)
    print("teststring 3:", teststring)
end
I create multiple text files, each holding about 200 characters worth of code. It seems to work fine in single player and I can use one ability and I don't have to worry about the levels. Is there a problem with having multiple files like this?
 
Last edited:
Status
Not open for further replies.
Top