Current Status of Lua Modding

LeeS

Imperator
Joined
Jul 23, 2013
Messages
7,241
Location
Illinois, USA
After running some tests and playing around with various methods, the following appears to be true:
  1. [fixed by Winter 2016 patch]Lua scripts that are activated in the modinfo file as "GameplayScripts" only load into the game when a new game is started. When a reload of a saved game is conducted, the lua script is not loaded along with the saved game.
    This concerns lua files that are set up in the modinfo file like as this:
    Code:
    <GameplayScripts id="LUA_CODE">
         <Properties>
              <Name>LUA_CODE_GAMEPLAY_CHANGES</Name>
         </Properties>
         <Items>
              <File>LUA_Code.lua</File>
         </Items>
    </GameplayScripts>
  2. Certain API methods (functions) only seem to work in certain context-types. So, for example, the API unit method "GetUnitType()" is not a valid function-name in a "GameplayScripts" context but appears to be valid in a UI context. Similarly, JFD tested and verified that "playerReligion:GetReligionTypeCreated()" is only recognized in a UI context, and when attempted from a "GameplayScripts" context simply causes a fatal syntax error to the lua file. This also explains why using
    Code:
    local iGrassMountains = GameInfo.Terrains["TERRAIN_GRASS_MOUNTAIN"].Index
    TerrainBuilder.SetTerrainType(pChosenPlot, iGrassMountains)
    and similar methods for the ResourceBuilder and FeatureBuilder seem to work in a "GameplayScripts" context but appear not to work in a UI context.
  3. The graphics issues on the main map for terrain alteration coming from a GameplayScript lua from Civ5 are alive and well in Civ6. You can alter the terrain, but in order to get the graphics to update, the player must save and then reload their game.
  4. The good news is that while undocumented as yet there appears to be a pairing of a "set" and a "change" with most "get" methods.

    So, playerReligion:GetFaithBalance() has a paired playerReligion:SetFaithBalance(iNewValue) and playerReligion:ChangeFaithBalance(iChangeAmount).

    These two specific examples have been tested by me and verified to work.
  5. It seems that only lua files that are replacements for existing basegame lua files can be Imported into the VFS system and included in another lua file. New lua files that are Imported and then Included seem not to work according to JFD.
 
Last edited:
Moderator Action: I think whilst LeeS and others are formulating the state of lua modding, it would be good to sticky it in this forum for now, pending a more descriptive thread once more discoveries have been made about lua in Civ 6. I've done this (after speaking with LeeS about it).
Please read the forum rules: http://forums.civfanatics.com/showthread.php?t=422889
 
Do custom UI screens not work yet? I thought I would experiment with one, tried loading as a UserInterface component and game would start to load, jump back to game setup, then I could hit play and game would load, but not custom file. I wasn't sure if there was some setting I was missing, or just doesn't work yet.
Sorry if this was already covered and I didn't see.

Edit: I think I may not be properly defining the context. How do I specify the context as ingame and a screen, currently I have name="ingame" in opening context line, and
Code:
 <Container        ID="Screens">
        <LuaContext ID="TestScreen"                          FileName="TestScreen"                            Hidden="0"  />
    </Container>
for the lua context, obviously not correct.
I didn't have problem adding screens in V, but I'm sure I'm missing something obvious, it is early here.:coffee:
 
Last edited:
Without example, not so simple...
 
After running some tests and playing around with various methods, the following appears to be true:
  1. Lua scripts that are activated in the modinfo file as "GameplayScripts" only load into the game when a new game is started. When a reload of a saved game is conducted, the lua script is not loaded along with the saved game.
    This concerns lua files that are set up in the modinfo file like as this:
    Code:
    <GameplayScripts id="LUA_CODE">
         <Properties>
              <Name>LUA_CODE_GAMEPLAY_CHANGES</Name>
         </Properties>
         <Items>
              <File>LUA_Code.lua</File>
         </Items>
    </GameplayScripts>
  2. Certain API methods (functions) only seem to work in certain context-types. So, for example, the API unit method "GetUnitType()" is not a valid function-name in a "GameplayScripts" context but appears to be valid in a UI context. Similarly, JFD tested and verified that "playerReligion:GetReligionTypeCreated()" is only recognized in a UI context, and when attempted from a "GameplayScripts" context simply causes a fatal syntax error to the lua file. This also explains why using
    Code:
    local iGrassMountains = GameInfo.Terrains["TERRAIN_GRASS_MOUNTAIN"].Index
    TerrainBuilder.SetTerrainType(pChosenPlot, iGrassMountains)
    and similar methods for the ResourceBuilder and FeatureBuilder seem to work in a "GameplayScripts" context but appear not to work in a UI context.
Anyone found a workaround ?

I'd really want to use functions available in a gameplay script context after reloading a game...

There is a "GameCore_Tuner" Lua state listed in the FireTuner which is a "gameplay script context", but can we hook on it ?
 
Lua scripts that are activated in the modinfo file as "GameplayScripts" only load into the game when a new game is started. When a reload of a saved game is conducted, the lua script is not loaded along with the saved game.
Did i understand this correctly as "we can't have Lua scripts affecting gameplay apart from the intialization" or is it just one way of loading them that doesn't work?
What if i wanted a Lua script for a custom trait like many Civ5 custom civs? Or one that changes yields or adds a dummy building? Are those currently possible as they were in Civ5 or are we limited to UI mods as far as Lua is concerned currently?
 
Did i understand this correctly as "we can't have Lua scripts affecting gameplay apart from the intialization" or is it just one way of loading them that doesn't work?
What if i wanted a Lua script for a custom trait like many Civ5 custom civs? Or one that changes yields or adds a dummy building? Are those currently possible as they were in Civ5 or are we limited to UI mods as far as Lua is concerned currently?
At the moment we are limited to UI. The other types of lua methods you are referring to require running from a Gameplay script because at the moment many lua commands are context-type dependant, and you need things like as an example a unit-captured event to run from a gameplay context rather than a UI context*. IE, some methods only work in a UI, and are not recognized in a gameplay script, and vice versa. Lots of stuff works in both types of context but it is pretty much hit or miss at the moment for the implementation of what works in which type of lua file.

* I tried to do that sort of thing as a work-around, but it locked the game because I needed to use a command that was only valid in a gameplay context, and it made the game lock up when it was attempted in a UI file.
Are the modding_loadmod procedures such as
Code:
('Modding_LoadMod', 'AddComponentFile', 'INSERT INTO ComponentFiles(ComponentRowId, FileRowId, Priority) VALUES (?, ?,?)');
just for adding a file to the mod (which I am not sure why you would want/need to in game, or do they actually add the file into the game?
StoredProcedures looks like it is how the game finds and reads the files from the mod(s) and loads them into the game. The issue would appear to be in the game's exe file, since a AgentRansack search shows both the phrases "Modding_LoadMod" and "StoredProcedures" as being what would look like executable code within the game's exe file. Other than that it's all @, $ and # in the same chunk of the exe code.
 
Last edited:
The scenarios implement gameplay changes, but only on first initialize of the game. Thought that was interesting.

The tutorial does more, but doesn't allow saving.
 
Yes, I hope it's just because those changes would not be a problem if they are called multiple times, not a sign that gameplay script are designed to run once...
 
Yes, I hope it's just because those changes would not be a problem if they are called multiple times, not a sign that gameplay script are designed to run once...

There is save functionality, with reloading in the tutorial script in the UI directory. But saving is turned off for tutorial, so perhaps they never got it working right?
 
The tutorial cheats, it has Lua files under base\assets that always run, as well as kludges in a number of other files, like Civ6Common.lua[712]:

Code:
function IsTutorialRunning()
    local mods = Modding.GetActiveMods();
    if mods ~= nil then
        for i,v in ipairs(mods) do
            if v.Id == TUTORIAL_UUID then
                return true;
            end
        end
    else
        UI.DataError("Unable to obtain mods table to determine if tutorial is running.");
    end
    return false;
end
 
Top Bottom