Putting the save game code in a function makes perfect sense.
You can also have arrays of integers in the save game, if that helps.
Another handy thing you can do is, just manage the whole save game thing in the game instance. When the game starts make sure you have a good reference, and then just setup a timer to save every couple of seconds or so.
Then all you have to do is get a copy of the reference variable elsewhere. Update that, and you know it’s getting written to file with no hassle.