Game saving and loading

  • #1, by tall-story-gamesWednesday, 06. January, 14:51 3 weeks ago
    Hi,
    I don't know if this is something I'm doing wrong, but I have a couple of issues with game saving/loading.

    Saving:
    I have set up the savegame slots as per the tutorial, but the current game always saves in the next available slot, as opposed to the slot that is actually selected. For the most part this isn't really a problem, but it "feels" like a bug if you've chosen one particular slot (e.g. slot 6) and it saves within another (e.g. slot 3 as it is the next available slot). I have downloaded the original savegame tutorial files and they have the same issue too.

    Loading:
    Immediately after a saved game is loaded, the interfaces appear in the top left hand corner of the screen, then readjust themselves a moment later. Is there a fix for this?
    I wondered about setting a condition to true just before each game is saved, then immediately setting it to false again once the game has been saved (essentially meaning that any loaded game has this variable set to true) then doing something with the interface based on this condition before resetting it again...but this feels like a bit of a hack.

    Thanks,
    Tom

    Newbie

    39 Posts


  • #2, by afrlmeWednesday, 06. January, 18:23 3 weeks ago
    That's how the save system works. If you select an empty slot it will always save into the first available empty slot & not the one you selected unless a save exists in the slot before the one you selected.

    As for the interfaces, I'd possibly recommend hiding them before you execute the save. I don't know why they would appear out of position when you first load a save game.

    Imperator

    6913 Posts

  • #3, by i-c-gWednesday, 06. January, 19:44 3 weeks ago
    Heh, we stumbled onto the same issue this afternoon!

    Our solution is to actually highlight a selected slot only if there is a savegame in it.
    Clicking in an "empty" slot deselects all of them, so if the user clicks "SAVE" it is not misled into thinking there is a bug.
    If the user selects an already occupied slot the system behaves as expected instead, so we highlight it.

    Should be pretty easy to do, my mate is taking care of it but we "debuged" it together.
    If you need more info I can collect them tomorrow and provide our solution.

    Cheers

    Newbie

    13 Posts

  • #4, by tall-story-gamesWednesday, 06. January, 19:58 3 weeks ago
    Thanks, that sounds like a good plan. I wanted to check if I was missing something first. I'll work on it tonight and see what I can work out ??

    Newbie

    39 Posts

  • #5, by tall-story-gamesFriday, 08. January, 17:55 2 weeks ago
    @i-c-g I think I've managed to come up with a fairly elegant solution to this which checks which savegame files are present in the local app directory and shows/hides the appropriate savegame slots accordingly.

    This is what I've done.

    I  created a function in the main script tab which checks for a savegame file based on a single digit number. If you pass it a 1 it will check that savegame00.dat exists and so on.

    This will only work with savegame files up to 9 unless you take into account the additional zeros within the file names. I only have 6 savegame slots in my game, you could just as easily pass it for full filename or simply "01", "02" etc. as a string and adjust the structure of the path variable accordingly.

    Here's the function:

    function checkSavegame(n)
      local f, path
      path = localAppDir .. "Savegames\\savegame0" .. (n-1) .. ".dat"
      f = io.open(path)
      if f then
        return true 
      else
        return false
      end
    end 

    I also created a condition for each savegame slot which I can use to show/hide them within their "Condition" property (see screenshot 1). Note that the condition used for each slot is the one from the preceeding savegame i.e. the Condition used to display slot 4 is "Save game 3 exists" as you only want to display this slot if the one before it is already full.

    I then created an action which runs on a loop within the save/load menu and changes each condition based on the lua result from the function above (see screenshot 2).
    This action is called when the save/load menu begins, and quit when it ends.

    Using the above conditions, I've also added a few additional actions to show/hide the slots when the game initially loads so you don't end up with a useless slot displaying when it's either empty or you've not started a saveable game yet, but I won't go into detail about that here.

    I hope this helps smile

    Newbie

    39 Posts

  • #6, by i-c-gFriday, 08. January, 23:59 2 weeks ago
    Hi  @tall-story-games.

    I was about to write you a post today, but I ran out of time. I came to a similar conclusion after a bit of work this morning. I took another route from a user perspective, but I'm also checking that savegame files are there.

    Allow me some hours to come back to you with an explanation of what I did, as well as to properly check out your version! smile

    Thanks for sharing!

    EDIT: just noticed "if lua result" actionpart... how could I miss it?! It's life-changing stuff! Now I'll streamline my work before sharing it! WOW! grin

    Newbie

    13 Posts

  • #7, by tall-story-gamesSaturday, 09. January, 08:37 2 weeks ago
    Brilliant, would love to see how you solved the same issue.

    When I discovered the "If lua result" actionpart a couple of months ago, I was able to go back and cut out tonnes of unnecessary code and actions, I prefer to keep as much code as possible within the actions ??

    Newbie

    39 Posts

Write post