UI - getting loaded file name (Solved)

Krauk0

Chieftain
Joined
Apr 9, 2017
Messages
2
Me and my friends like to play civ 5 "by email", and thus there is a lot of loading and saving of hotseat games going on. In an effort to reduce the amount of clicking, I have made a modified version of the load menu (LoadMenu.lua and LoadMenu.xml) which opens when civ opens and loads the file with just 1 click.

I would now like to modify the save menu (SaveMenu.lua and SaveMenu.xml) so that it, upon clicking the "Save game" button in the player changer menu, automatically saves the game, using the same name of the file that was loaded. Passing any arbitrary string to the save function was easy, but I'm having trouble getting the name of the file from the load menu. I've tried to read about UI mods, but what I find is mostly related to in game UI.

What I've tried so far:

- Calling Pregame.GetLoadFileName(). I thought this was supposed to persist even in game? However, I found some indications that this is only applicable for multiplayer games (and hotseat games are not technically considered multiplayer), if I understand things correctly? It is empty when I am in game, and even if i set the name manually when loading the file, it is still empty when trying to save.

- Storing the string in mapmoddata. I encountered an error trying to create the tables, and checking with Fire Tuner, I don't think mapmoddata is created until the map has been created, which is obviously too late in my case.

- Creating a global variable to which both LoadMenu.lua and SaveMenu.lua can write/read. So far all my attempts have simply resulted in there being a separate variable for both files. In other words, adding this to LoadMenu.lua:
Code:
g_FileName = "Empty";

function OnStartButton()
      (...other stuff...)
        g_FileName = "MySaveFile";
      (...other stuff...)
end
and then trying to read g_FileName from SaveMenu.lua only shows "Empty". I've tried several variants, including using LuaEvents to edit or get the variable but still the same result. No difference if I place the variable in LoadMenu or SaveMenu, or in any other lua file for that matter.

How can I make the variable truly global? Or is there some other way I can store the string? Or perhaps there is another way to get the file name when I am already in game?

Any and all help is greatly appreciated!
 
I've been trying this for two days now, and obviously the next thing I try solves the problem. In hindsight, perhaps this should have been obvious as it seems to be made for this kind of thing, but I hadn't come across it. Must have been looking in the wrong places I guess.

Anyway, just in case someone needs it, I'll say that I placed "Modding.OpenSaveData().SetValue("FileName", thisLoadFile);" in a strategic place in LoadMenu.lua and then in SaveMenu.lua "Modding.OpenSaveData().GetValue("FileName")" to recall it. This gets the full path and includes the file ending ("c:\\users\\[.....]\\MySaveFile.civ5save"), but there are functions in both SaveMenu and LoadMenu that can take out only the display name.
 
Back
Top Bottom