Saving from DLL

psparky

King
Joined
Feb 24, 2011
Messages
623
Can I save to a named file from within the DLL?

In LUA, this works (example from IGE):

UI.SaveGame(fileName, true);

I tried:

DLLUI->SaveGame("MYSAVE");

which gives the error:

'SaveGame' : is not a member of 'ICvUserInterface2'

Thanks for any guidance.
 
Edit: Ignore previous answer, I mis-read the question.

Yes, see my first DLL tutorial for how to write to a log file

Edit 2: And still mis-reading the question. You can any data to a log file, can you save the game state, no
 
Ok, thank you for trying. A bit annoying as the function I need is there but I guess there is no way to reference it from the DLL.

My fallback plan is to add a GameEvent (using your tutorial) and call the SaveGame function from LUA. Do you think that will synchronise properly - that the DLL will wait for the LUA handler to complete?

What I'm trying to do is to automatically save the game at the end of my turn before the AI players have their turn. I am currently calling QuickSave (which is visible in the DLL) at the appropriate place and the saves I'm generating seem to work, but I would prefer to name them similar to autosaves.
 
GameEvents are async, so no, the DLL won't wait for the Lua to complete. There is a comment I left in the code that alludes to this.

Why not use the C++ file functions to rename the autosave file?
 
I guess I could do a quicksave and rename the file. I find the default autosaves annoying so I'm trying to replace them with my own that occur at a more useful time. My saves occur when you click next turn but before your click is actioned. When reloaded, the next turn button is available to click, or you can take actions before you click. The existing autosaves occur after the AI players have had their turns, basically at the start of your next turn.

There are two advantages:

1. When I'm tweaking or investigating game mechanics and something interesting happens on the AI's turn, in order to reproduce the situation (to add logging or run with debug) I have had to load the previous autosave and replay my last turn. Sometimes that changes things so the interesting situation doesn't even occur. With my new save I'm good to go.

2. If I forget to do something critical that will ruin my game (like actually make peace with someone :) ), I can put it right without having to replay the last turn.

I've actually stumbled on something that works. I'm now calling autosave with the second parameter set true, which creates a file called AutoSave_Post_<turn>. I didn't change the setting in the config file that usually causes these files to be generated, otherwise my file would get overwritten by the game. I now end up with two autosaves for each turn, the default one and the one I'm triggering myself.
 
Top Bottom