Save game data

  • #1, by minibigsFriday, 16. January 2015, 01:35 10 years ago
    Hi, I'm completely new to VS & LUA so please bear with my ignorance.

    I want to be able to detect which savegame is going to be saved & write an associated file containing my own values to disk by executing an appropriate script at save game time.

    I can do all the IO / disk operations & scripting bits, but am struggling to pull the info off the VS data structure, as this is the first time I have done this.

    I tried the following :

    local ff = game:getLink(VGameSaveGameName)
    local ff = game:getLink(VGameId)

    Both come up as empty.

    Basically, I need some way to associate my own files with a particular savegame file, so it can be retrieved if the game is reloaded.

    Any help / ideas appreciated,

    Cheers,
    Steve

    Newbie

    79 Posts


  • #2, by SimonSFriday, 16. January 2015, 01:43 10 years ago
    Hi, don't do everything twice, VS saves all your variables in lua into the savegame. Only closures, metatables and tables marked with _temporary_ are not saved.

    Thread Captain

    1590 Posts

  • #3, by afrlmeFriday, 16. January 2015, 01:53 10 years ago
    You need to pay closer attention to what sort of field you are accessing.

    SaveGameName is a t_string & so is the GameId field.

    If you want to access them with the longhand method you are using above then it would be...
    game:getStr(VGameSaveGameName)
    game:getStr(VGameId)
    

    Although you can actually access game fields since vs4.1 with the new shorthand code like so...
    game.SaveGameName
    game.Id -- not 100% on this one. Typically shorthand removes initial word, but not in all cases.
    


    Question: why are you doing this? Can you not input the data into values/conditions etc inside of VS?

    Imperator

    7285 Posts

  • #4, by minibigsFriday, 16. January 2015, 01:55 10 years ago
    Another thing I noticed & forgot to ask is that the savegame path is different to the path VS stores files created by LUA scripts in.... savegame path is in /users/blah/appdata/local/blah, LUA script path is to the folder containing the VED file.

    Is there a way to force path change / code explicit save path so as to get both in the same folder to keep things tidy?

    Cheers,
    Steve

    Newbie

    79 Posts

  • #5, by minibigsFriday, 16. January 2015, 02:07 10 years ago
    I plan to store game comments, descriptions, achievement awards, bonuses, etc.

    Thanks for the super quick help. VGameSaveGameName returns 16.1.2015, 0:15h, which doesnt seem to compute?


    Newbie

    79 Posts

  • #6, by afrlmeFriday, 16. January 2015, 02:07 10 years ago
    Actually not sure. In 3.7.1 & below the save folder was located in the .ved root folder & you could also create your own config.ini inside of the .ved root folder too.

    Does it still generate the files inside of user > ... with a compiled version of the game? According to the data structure it shouldn't do that unless a game name &/or company name has been provided.

    I'm still unsure as why you are wanting to mess around with the save stuff. Also a lot of games these days store save files & .cfg/.xml files inside of documents or app data to prevent the save files & users settings from being deleted if the user decided to uninstall the game.

    Imperator

    7285 Posts

  • #7, by afrlmeFriday, 16. January 2015, 02:16 10 years ago
    I plan to store game comments, descriptions, achievement awards, bonuses, etc.
    Thanks for the super quick help. VGameSaveGameName returns 16.1.2015, 0:15h, which doesnt seem to compute?


    Actually that is correct. If you specify a text to be used for the save games via the properties tab, you will see that it displays a time stamp (date & time) underneath the generated save game thumbnail.

    There's a much simpler way to go about with what you are doing. Use the quick save (autosave) system. On new game add an if query if autosave #0 exists else execute autosave #0. Now this file will only be generated once. Next you need to figure out when to overwrite it. The autosave system is great for setting up a resume/continue function for your game as you can execute (save) it each time you load a new scene, leave a scene, do something important in the game or maybe before or after you access the games menu.

    P.S: you could write the data into an external file no problem & read the data on the file at game launch but unless you plan on using encryption for the data (sha-1 or whatever - I forget) then it's not the most secure method as people would simply be able to edit the file & add data into if they know what it is & thus would be able to unlock all achievements, collectibles without batting an eyelid.

    Imperator

    7285 Posts

  • #8, by minibigsFriday, 16. January 2015, 02:23 10 years ago
    I was actually trying game:getTextStr(VGameSaveGameName) as well as game:getLink(VGameSaveGameName). This didn't return anything either, my bad as a newbie I just plucked it out of the manual.

    You are correct, I could store is all just as easily in values/conditions.

    The only thing missing seems to be a way to get say 60 char. text strings in from the user... it would be neat to
    do that as part of the save game menu.

    Regards,
    Steve

    Newbie

    79 Posts

  • #9, by minibigsFriday, 16. January 2015, 02:29 10 years ago
    Aha... A light bulb when on above my head when I read your bit about autosave... with that & the rest of your info I can see the need for additional save files disappearing into the distance.

    Newbie

    79 Posts

  • #10, by afrlmeFriday, 16. January 2015, 02:36 10 years ago
    Hmm... theoretically possible, but not without a lot of work. It would require you to use values (containing strings) with display object text actions or animations to display the names & some method of utilizing key input, which is possible with both the key action system (would require a lot of work) & with Lua in combination with the key event handler via the registerEventHandler function (would also require setting up / scripting).

    All of which is no simple matter.

    * edit: yes the autosave (not sure why it's called that as it needs to be manually triggered) is one of the most useful functions of Visionaire Studio as it can be used on both playable scenes & menu scenes. You can create as many autosaves as you like too. I tend to use 1 for new game & 1 for resuming from last played game. As for game options I use a custom script that writes & reads the options to/from the config,ini file. It's faster & more reliable than using autosave files, plus the config.ini file is ok for players to edit if they like as it usually only contains game menu options.

    Imperator

    7285 Posts

  • #11, by BarneyFriday, 16. January 2015, 10:33 10 years ago
    Hey, regarding savegames... For some reason the autosave in my game doesn't work in the compiled version. It loads perfectly well when I use the "Save and run" option, but after the game is compiled - nope. Maybe I'm forgetting something?

    Newbie

    42 Posts