Modding SelectDifficulty.lua to refresh the difficulty list in Basic game setup

MyopicCat

Chieftain
Joined
Jan 6, 2014
Messages
73
Disclaimer: I'm a complete newbie (in both Civ modding and Lua), so please go easy on me.

I've created an XML mod that adds new difficulty levels, and I want them to show up on the basic game setup screen. Not entirely trivial, because by default they only show up on advanced setup.

I've looked through the Lua code in \Assets\UI\FrontEnd\GameSetup, and I think I've found the problem. SelectDifficulty.lua only populates the difficulty list once. So I modified the code slightly to repopulate the difficulty list when the AfterModsActivate event fires.

For some reason, my mod doesn't work. Since I can't find my diagnostic messages in the log files, I suspect my Lua code isn't even running. I've just copied the existing SelectDifficulty.lua to my mod, changed it, flipped the "import into VFS" flag to true and thought that it would replace the existing file automatically. Is this assumption wrong? Can anyone see why my code isn't working?
 

Attachments

  • MC Hello World.civ5mod
    2.8 KB · Views: 65
When I said go easy on me, I didn't mean THAT easy ... :)

I'm still fumbling in the dark, so I'll throw out a few other possible explanations:

1. Could my Lua actually be running, but my print statements are not being logged for some other reason? What could that reason be, if everything else is being logged to lua.log?

2. Is the basic game setup screen unmoddable for some obscure reason?

3. Can someone please confirm that, in principle, a modded version of a core LUA file will automatically replace the original if "import into VFS" is true and the filename is unchanged? As far as I can tell from whoward69's guide here it should work:
http://forums.civfanatics.com/showthread.php?t=487846
 
I've not looked at your mod, but in general the menu xml/lua files behave differently as they can be loaded and cached before any mods are loaded. This is especially true of files that are are used by both the non-mod menu system and the post-mod menu system. Pretty sure SelectDifficulty falls into this camp. So even with the same name and VFS set to true, you're replacement file in the mod won't be used as there is a cached version in use before your mod is loaded.

One way to find out if your file is being used is to place a print("This is the replacement SelectDifficult.lua file") as the very first line of the file. If that displays in the lua.log file, the replacement is in effect, if not, then the original is being used. In the latter case, the only way to get the replacement file to be used would be by changing your mod to a pseudo-DLC, a la EUI.
 
Thank you very much! I'll move my print statement to the first line and test again.

But it seems that this is bad news for my mod - it's a simple difficulty mod and I don't want a complicated installation procedure. I hoped to hijack the basic Select Difficulty list to highlight my nice new icons I spent an entire afternoon designing. The mod works via Advanced Setup, but only as a drop down list with text.

So typical that this is just about the one thing that can't be done (easily) ...
 
Some tests, see attached mod.

(Before starting the test you will need to edit the core game front end .lua files and add a print as the first line to identify them.)

The test was to start civ, navigate directly to the Mods menu, enable the mod, navigate into the setup screen, choose each menu option (civ, map, speed, etc), navigate into the Advanced Setup screen, edit the civ name and then start the game. Wait for it to load and get to turn 1, then exit straight to windows.

Of the 34 .lua files that comprise the single player front end menus ...

27 of those are loaded and (possibly) used BEFORE a mod can change them
  • UI\FrontEnd\ContentSwitch.lua
  • UI\FrontEnd\ExitConfirm.lua
  • UI\FrontEnd\FrontEnd.lua
  • UI\FrontEnd\FrontEndPopup.lua
  • UI\FrontEnd\LegalScreen.lua
  • UI\FrontEnd\LoadMenu.lua
  • UI\FrontEnd\LoadTutorial.lua
  • UI\FrontEnd\MainMenu.lua
  • UI\FrontEnd\OtherMenu.lua
  • UI\FrontEnd\PremiumContentMenu.lua
  • UI\FrontEnd\ScenariosMenu.lua
  • UI\FrontEnd\SinglePlayer.lua
  • UI\FrontEnd\ToolTips.lua
  • UI\FrontEnd\GameSetup\GameSetupScreen.lua
  • UI\FrontEnd\GameSetup\SelectCivilization.lua
  • UI\FrontEnd\GameSetup\SelectDifficulty.lua
  • UI\FrontEnd\GameSetup\SelectGameSpeed.lua
  • UI\FrontEnd\GameSetup\SelectMapSize.lua
  • UI\FrontEnd\GameSetup\SelectMapType.lua
  • UI\FrontEnd\GameSetup\SetCivNames.lua
  • UI\FrontEnd\GameSetup\UniqueBonuses.lua
  • UI\FrontEnd\Modding\CustomMod.lua
  • UI\FrontEnd\Modding\EULA.lua
  • UI\FrontEnd\Modding\InstalledPanel.lua
  • UI\FrontEnd\Modding\ModsBrowser.lua
  • UI\FrontEnd\Modding\ModsMenu.lua
  • UI\FrontEnd\Modding\ModsSinglePlayer.lua

5 of those are reloaded and 2 additional files loaded and used and can be changed by a mod AFTER the Mod Browser screen
  • UI\FrontEnd\ContentSwitch.lua
  • UI\FrontEnd\ExitConfirm.lua
  • UI\FrontEnd\LoadMenu.lua
  • UI\FrontEnd\LoadScreen.lua
  • UI\FrontEnd\GameSetup\AdvancedSetup.lua
  • UI\FrontEnd\GameSetup\SetCivNames.lua
  • UI\FrontEnd\GameSetup\UniqueBonuses.lua

And 5 didn't fall within the test
  • UI\FrontEnd\Credits.lua
  • UI\FrontEnd\LoadReplayMenu.lua
  • UI\FrontEnd\PreGameScreen.lua
  • UI\FrontEnd\WorldPicker.lua
  • UI\FrontEnd\Modding\ModsError.lua
 
From memory, my mod changes all of these:

UI\FrontEnd\GameSetup\AdvancedSetup.lua
UI\FrontEnd\GameSetup\GameSetupScreen.lua
UI\FrontEnd\GameSetup\SelectCivilization.lua
UI\FrontEnd\GameSetup\SelectDifficulty.lua --xml edit only
UI\FrontEnd\GameSetup\SelectGameSpeed.lua --xml edit only
UI\FrontEnd\GameSetup\SelectMapSize.lua --xml edit only
UI\FrontEnd\GameSetup\SelectMapType.lua --xml edit only
UI\FrontEnd\LoadScreen.lua
UI\FrontEnd\ExitConfirm.lua

The effects are quite apparent in all cases.

What I haven't done is a very rigorous workout with the Back button and swapping between mod and non-mod. Could be problems there but it's not something I worry about.
 
My experiences are inline with whoward69's tests: AdvancedSetup.lua can be modded, but SelectDifficulty.lua and GameSetupScreen.lua cannot.

Pazyryk, could you please doublecheck that your mod really changes GameSetupScreen.lua? If so, how did you do it? Changes I make to this file have no effect.
 
Mystery solved.

Executive summary: Pazyryk - never upgrade your mod from G&K to BNW

EA has a "depends" on G&K and a "blocks" on BNW. By putting the same onto the test mod, EVERY one of the 27 files in the first list are reloaded, which means a G&K only mod can change any file in the front-end menus, whereas a BNW mod can only change the 7 in the second list.

That's a surprising step backwards between the two expansions. :confused:
 
That's a surprising step backwards between the two expansions. :confused:

Edit: It's a difference in the way the mod/dlc code is loaded/unloaded during game configuration - see post #13 below
 
Too late. I already upgraded to BNW in my current build (not yet released). I'm looking at Dependencies right now:

Expansion - Gods and Kings
Ea Media Pack
Genghis Khan's Mongolia
Expansion 2 - Brave New World

All other DLC appear in the Blocks section (the final entry is "DLC - Block All Other DLC").

The mod has extensive changes to many front end UI elements, all of which appear to be functioning. You can see the effects of GameSetupScreen.lua/xml and SelectCivilization.lua/xml modding below. All of the other Select___.xml's were modified to fit the altered window size. All of this is functioning in the BNW version:



I don't remember having to do anything in these particular files when I upgraded to BNW. The Fall patch required an update of SelectMapType.xml.

Perhaps the key is depending on BNW and G&K. It didn't occur to me to drop G&K when adding BNW.
 

Attachments

  • Setup screen.jpeg
    Setup screen.jpeg
    285.6 KB · Views: 508
Setting the test mod to depend on both gives the same results as depending on none ...
 
Second part of the mystery solved. It's the "auto-block DLC" feature.

EA also depends on Mongolia, but more importantly blocks the other DLC (Spain, Polynesia, Wonders, et al)

Adding a "blocks Spain" to the test mod produces the same results as "blocks BNW".

Except that's not the complete story.

Start Civ, navigate to mod browser, enable test mod, start game (at this point the game auto-blocks Spain as part of the "configuring data" screen) - you see the modded front end lua files.

BUT

Start Civ, nav into DLC menu, disable Spain, click OK (you get a "configuring data" screen here), nav into mod browser, enable mod, start game (another "configuring data" screen) - and you DON'T get the modded front end lua files (because the front end was reloaded as part of taking Spain out not putting the mod in and we've changed where taking Spain out occurred)
 
Ouch! So it depends on having some DLC and then the mod blocking it? The only extra DLCs I have are Mongolia, Babylon, G&K and BNW. So does it work for me only because I have Babylon?

Would it work by blocking Mongolia? At least that's universal for players -- but it would break if they (for some reason) had manually disabled Mongolia from DLC screen...
 
Ouch! So it depends on having some DLC and then the mod blocking it?
That's my conclusion
- no blocks, front end mods don't load
- only depends, front end mods don't load
- blocked DLC not enabled, front end mods don't load
- blocked DLC enabled such that it has to be auto-disabled, front end mods load

The only extra DLCs I have are Mongolia, Babylon, G&K and BNW. So does it work for me only because I have Babylon?
That would be my assumption. You could test this by starting Civ, nav into the DLC menu, disable Babylon, exit back to main menu (you will get a configuring data screen here), nav into the mods browser, enable EA, click next (another configuring data screen) but I'm guessing you won't see your front end mods now.

Would it work by blocking Mongolia? At least that's universal for players -- but it would break if they (for some reason) had manually disabled Mongolia from DLC screen...
Not tried, as EA is marked as depends on Mongolia
 
Not tried, as EA is marked as depends on Mongolia
I'll try moving it to Blocks. If it works, this would give me a workaround that works for all players, and is only slightly awkward. All players have Mongolia DLC, right?

I also wonder if the "DLC - Block All Other DLC" would do this by itself. Probably not, I guess, unless the player had some other DLC enabled for the mod to block.
 
Slightly off topic, but I've noticed a couple other situations where having DLC installed (but not enabled) matters:

1. When BNW first came out, new owners (but not non-owners) suddenly had missing text in my G&K mod. I tracked that down to the three text keys associated with GetScenarioDiploModifier1, 2 & 3. BNW-owners already have these text keys, non-owners didn't. So my mod adding them with INSERT was causing all text in that file to fail. Easy fix with REPLACE once I knew the problem.

2. For some reason, when I updated my G&K mod from v16 to v17 in November, I did something that made it unplayable unless you own BNW, even though the mod blocks it. It's not the setup screen. Something else that ultimately corrupts mod data. (I haven't tracked this down because a BNW version is forthcoming and I'm not maintaining a G&K version.)
 
Wow, amazing! If I block any DLC in my mod, then I finally see my custom difficulties in the basic game setup, even without a custom SelectDifficulty.lua!!!

The only problem left now is that I would like my mod to work with all DLC ... :)

But perhaps there is a workaround. Blocking G&K seems to work. Since G&K is completely (?) contained within BNW, this should have no effect on BNW users, correct? And of course it shouldn't affect Vanilla users either. Then, for the poor G&K users out there, I can release a *separate* version of my mod in which I block BNW.

So am I right that blocking G&K in my mod would work without any restrictions to BNW users with extra DLC?

Thanks whoward69 for all your research into this!
 
So am I right that blocking G&K in my mod would work without any restrictions to BNW users with extra DLC?

Your suggested approach only works for player who have BOTH expansions and are playing with one or the other. It wouldn't work for players with only one expansion (either G&K or BNW) as the other won't be enabled by default (as they don't own it) so it will not be auto-disabled, so the front end files won't be reloaded.
 
Top Bottom